NGINX配置PHP网站

  • NGINX配置PHP网站
    • 源码安装NGINX
    • 安装PHP
    • 修改PHP参数
    • 重启PHP
    • 修改nginx配置文件
    • 重启NGINX
    • 测试
    • 解决报错问题

NGINX配置PHP网站

源码安装NGINX

脚本一键安装:
安装路径:/opt/nginx
源码路径:/root/

 #!/bin/bash
useradd -s /sbin/nologin nginx               #创建一个不能登陆系统的用户nginx#Installation dependence
yum groupinstall -y "Development tools"
yum install -y gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
yum install -y pcre-devel pcre zlib zlib-devel openssl openssl-devel wget gcc gcc-c++ unzip
yum -y install git#Download source
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -xvf nginx-1.20.1.tar.gz -C /opt#Compile and install
cd /opt/nginx-1.20.1/
sed -i '49s/nginx/Microsoft-IIS/' src/http/ngx_http_header_filter_module.c
sed -i '50s/: /: Microsoft-IIS/' src/http/ngx_http_header_filter_module.c
sed -i '51s/: /: Microsoft-IIS/' src/http/ngx_http_header_filter_module.c
./configure \
--prefix=/opt/nginx/ \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module
make && make install
ln -s /opt/nginx/sbin/nginx  /usr/bin/nginx
nginx
ps -aux|grep nginx

安装PHP

wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install -y ./remi-release-7.rpm
yum install -y php72-php-devel php72-php-fpm php72-php-mbstring php72-php-memcache php72-php-redis php72-php-mysqli php72-php-mysqlnd php72-php-pdo php72-php-bcmath php72-php-dom php72-php-gd php72-php-gmp php72-php-igbinary php72-php-imagick php72-php-mcrypt php72-php-pdo_mysql php72-php-posix php72-php-simplexml php72-php-opcache php72-php-xsl php72-php-xmlwriter php72-php-xmlreader php72-php-xml php72-php-swoole php72-php-zip php72-php-fileinfo curl curl-devel net-snmp net-snmp-devel perl-DBI ntpdate libxml2-devel libevent-devel yum-utils pcre pcre-devel openssl  openssl-devel zlib zlib-devel gcc gcc-c++

修改PHP参数

路径:/etc/opt/remi/php72/php-fpm.d/www.conf

vim /etc/opt/remi/php72/php-fpm.d/www.conf
修改参数:
max_execution_time=300 #修改为300
post_max_size=16M
upload_max_filesize=8M
max_input_time=300

date.timezone=“Asia/Shanghai” #增加
always_populate_raw_post_data=-1 #增加

重启PHP

systemctl restart php72-php-fpm

修改nginx配置文件

方法一:在默认的nginx.conf修改
方法二:添加conf.d 目录增加配置文件添加PHP配置

推荐方法2
方法一:
cp -r /opt/nginx/conf/nginx.conf /opt/nginx/conf/nginx.conf.bak
vim /opt/nginx/conf/nginx.conf +65

往下拉到 location ~ .php$位置

  1. 按 L或者右方向键到#号
  2. Crtl+v 可视化选项
  3. 按 j 键往下拉或按方向箭头往下键选中要取消注释的配置
  4. 再按 s 键就会把# 号去掉了
  5. 修改配置
    把 fastcgi_params 更改为fastcgi.conf ;注释掉这行 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

方法2:
默认文件配置文件不用修改 /opt/nginx/conf/nginx.conf
或者重新写入默认配置文件。这个是经常使用的nginx配置文件可以粘贴覆盖默认文件 /opt/nginx/conf/nginx.conf

worker_processes  auto;
error_log       logs/error.log error;
pid     logs/nginx.pid;
events { worker_connections  65535;multi_accept on;
}http {include    mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log     logs/access.log main;keepalive_timeout  60;add_header Access-Control-Allow-Origin '*';add_header Access-Control-Max-Age '3628800';add_header Access-Control-Allow-Credentials 'true';add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';add_header Access-Control-Allow-Methods 'GET,POST,PUT,OPTIONS';underscores_in_headers on;   client_header_buffer_size   32k;client_body_buffer_size  20m;client_max_body_size 120M;client_header_timeout   1m;client_body_timeout       1m;proxy_connect_timeout    600;proxy_read_timeout       600;proxy_send_timeout       600;large_client_header_buffers 4 32k;fastcgi_buffers      4 128k;fastcgi_buffer_size     128k;fastcgi_busy_buffers_size   256k;server_tokens off;tcp_nopush on;tcp_nodelay on;sendfile        on;gzip  on; #开启gzip#gzip_static on;gzip_vary on;gzip_min_length 1k;gzip_buffers 8 32k;gzip_http_version 1.1;gzip_comp_level 6; gzip_proxied any;gzip_types application/javascript application/json text/css image/png;real_ip_header        X-Real-IP;proxy_set_header        Host            $host:$server_port;proxy_set_header        X-Real-IP       $remote_addr;proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;   include      /opt/nginx/conf.d/*.conf;
}

添加子目录
mkdir /opt/nginx/conf.d
touch /opt/nginx/conf.d/test_php.conf

添加php项目
vim /opt/nginx/conf.d/test_php.conf

server {listen      80 ;server_name  localhost;location / {root   /home/test;index  index.php index.htm index.html;}location ~ \.php$ {root          /home/test;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;#fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;include        fastcgi.conf;}}

重启NGINX

nginx -t
nginx -s reload

测试

vim /home/test/test.php

<?php$i="This is a test Page";echo $i;
?>

解决报错问题

部署项目后:
如果出现 No input file specified.
看项目下面是不是多了 .user.ini文件
ls -la 查看项目下面

NGINX配置PHP网站相关推荐

  1. nginx配置前端网站

    原文链接:nginx配置前端网站 0.前言 上面一篇文章中,简单介绍了windows下下载安装nginx.这篇文章继续介绍下nginx下配置前端网站等. 1.配置文件 nginx的配置文件在下面的目录 ...

  2. Nginx配置web网站维护页面--->访问任意页面都要跳转到维护页面

    1.网站维护页面背景 网站升级需要停服的情况下,需要准备维护页面,单单准备一个维护页面也是不够的,很多用户会把登陆页面比如login.html收藏,这时访问项目就会出现404,因此还需要配置不管访问什 ...

  3. nginx 配置后网站图片加载出来一半或者不出来

    项目进行nginx反向代理后发现图片和js.css等加载很慢,甚至加载不出来. 然后查看nginx的log,发现错误如下: [html] view plaincopy 2016/06/30 15:31 ...

  4. 轻松搞定 Nginx 配置的好工具!

    轻轻松松,配置高性能.安全.稳定的 Nginx 服务器 无论是前端.后端.还是运维同学,都一定听说过 Nginx,一个高性能的 HTTP 和 反向代理 web 服务器,同时也提供了IMAP/POP3/ ...

  5. 轻松搞定 Nginx 配置代码的神器!

    轻轻松松,配置高性能.安全.稳定的 Nginx 服务器 无论是前端.后端.还是运维同学,都一定听说过 Nginx,一个高性能的 HTTP 和 反向代理 web 服务器,同时也提供了IMAP/POP3/ ...

  6. Linux下nginx配置证书实现https访问

    Linux下nginx配置证书实现https访问 一.下载并安装nginx (1)执行下列命令安装Nginx.yum install -y nginx 参考自https://www.cnblogs.c ...

  7. php默认访问的文件,PHP 网站修改默认访问文件的nginx配置

    这篇文章主要介绍了PHP 网站修改默认访问文件的nginx配置,需要的朋友可以参考下 搭建好lnmp后,有时候并不需要直接访问index.php,配置其他的默认访问文件比如index.html这时候需 ...

  8. linux location root访问文件夹404_如何使网站支持https访问?nginx配置https证书

    购买SSL证书 要想使用https访问你的网址,首先得拥有颁发的SSL证书.我使用的是免费版,有效期为一年,过期后再重新申请. 申请SSL证书 购买后,可在搜索框输入证书关键字进入到控制台. 点击证书 ...

  9. nginx配置一个简单的php网站遇到的问题

    安装完nginx后,想查看nginx的位置,可以通过查看软件安装路径命令 whereis nginx 这里的/usr/local/nginx/ 即是nginx的安装位置,配置文件在 /usr/loca ...

最新文章

  1. clickhouse hbase性能对比_QQ音乐PB级ClickHouse实时数据平台架构演进之路
  2. 给爸妈最硬核的春节礼物,走入百度大字版APP研发幕后
  3. Dropbox推独立应用,公司估值已达100亿美元
  4. 31 PP配置-生产车间控制-定义计划策略组
  5. logo下方显示技术支持信息_LOGO墙形象设计的几种方案
  6. 理解WebKit和Chromium: Content API和CEF3
  7. 【专利】实用新型专利设计模板
  8. 基于MATLAB的模糊聚类
  9. 桥牌笔记:机会最多的打法
  10. jupyter中subplots_adjust()调整子图大小无效、子图溢出和日期标签遮挡坐标轴刻度的问题解决
  11. 162天,从华为外包5k转岗正式员工15k,心酸只有自己知道
  12. bat 命令返回结果_bat教程[283] zip压缩
  13. 《Java编程培训教程》
  14. Oracle11g 调整表空间大小 Resize
  15. Linux 内核树编译
  16. 民宿OTA运营有哪些指标数据最重要
  17. `spyder总是闪退?spyder打不开?spyder又又又又又出错啦?
  18. TileColor快速指导:注册ocx文件
  19. 读《人性的弱点:如何赢得友谊并影响他人(完整版插图本》
  20. 他成绩一般,大二却破解世界难题,三院士致信中央,22岁破格成教授

热门文章

  1. 实战篇:GBase 8a MPP Cluster 安装部署过程
  2. 进程的三种基本状态及转换
  3. Cocos2dx物理引擎(一)
  4. 想问题(CoreIDRAW)
  5. java实现发红包案例(一)
  6. live mail的备份
  7. 寡头时代将至:前五大厂商占据中国手机市场91%份额
  8. Mysql主从复制—判断是否延迟
  9. sliverlight有关下载
  10. 内网渗透(windows)