nginx配置文件:
Nginx 默认使用 include enable-php.conf; 通过enable-php.conf 来解析PHP,该文件内容如下
location ~ [^/].php(/|$) { try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; }
而我们使用nginx自然要使用fastCGI来跑PHP,Nginx之所以并发高跟fastCGI脱不开关系,有自动管理php-cgi进程的能力,总之就是它很屌,使用Nginx不用fastCGI的话就好像抽烟不点火。
因此我们看到 Nginx的配置文件中有 :include enable-php.conf; 这行代码的话,有两种方法
1、请自觉在前面加个#注释掉~
然后添加一个类似的location,下面是例子
location ~ [^/].php(/|$) { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; # fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include /usr/local/nginx/conf/fastcgi.conf; fastcgi_split_path_info ^((?U).+.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; #该参数正常情况下应打开,如果报错access deny 且常规方法无法解决时 请注释掉 include /usr/local/nginx/conf/fastcgi_params; }
2、第二种解决方式,仍然引用enable-php.conf文件,但是需要修改此文件
[root@ACA83229 conf]# cat /usr/local/nginx/conf/enable-php.conf location ~ [^/].php(/|$) { try_files $uri =404; #fastcgi_pass unix:/tmp/php-cgi.sock; //注释掉此行代码,下面新写一行,使用9000端口 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; }
然后重启php-fpm 和 nginx, service不行的用systemctl命令。
service php-fpm restart
service nginx restart
OK。
结束