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。
結束
