1.nginx 配置完后 出现 404.
遇到这种情况, 第一个想到是 nginx 与 PHP 没有配置 pathinfo 的问题.
解决方法: nginx.conf 加上这段
- location ~ .+\.PHP($|/) {
- set $script $uri;
- set $path_info "";
- if ($uri ~ "^(.+\.php)(/.+)") {
- set $script $1;
- set $path_info $2;
- }
- fastcgi_pass unix:/tmp/PHP-CGI.sock;
- fastcgi_index index.PHP?IF_REWRITE=1;
- fastcgi_param PATH_INFO $path_info;
- fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
- fastcgi_param SCRIPT_NAME $script;
- include fastcgi_params;
- }
- 2.PHP.INI
- CGI.fix_pathinfo=1
1.nginx 配置完后 出现 500.
遇到这种情况, 想到的是 open_basedir 错误.
最后发现是 (在 nginx 配置目录) fastcgi.conf 中的 open_basedir 在捣鬼, 将:
"open_basedir=$document_root/:/tmp/:/proc/"
改成:
"open_basedir=$document_root/../:/tmp/:/proc/"
或者干脆把这行注释掉, 问题解决
3.nginx 配置完后 出现 502.
遇到这种情况打开日志 出现: connect() failed (111: Connection refused) while connecting to upstream
现在需要查看一下是否有监听 9000 端口:
[[email protected] /]# netstat -ant | grep 9000
发现并没有监听到, 但实际上我们的 PHP-fpm 已经启动, 那现在怎么办呢?
我们去查看一下 PHP-fpm.conf 里面的配置:
[[email protected] /]# VIM /usr/local/PHP/etc/PHP-fpm.conf
找到 listen:
<value name="listen_address">/tmp/PHP-CGI.sock</value>
此时我们需要根据配置文件的 listen 地址做对应的修改:
- location ~ \.PHP$ {
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.PHP;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
改成:
- location ~ \.PHP$ {
- fastcgi_pass unix:/tmp/PHP-CGI.sock;
- fastcgi_index index.PHP;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
- Access denied
在 PHP.INI 配置
将 CGI.fix_pathinfo 的值改成 1
最后成功的配置
- server {
- listen 80;
- server_name localhost;
- access_log /home/wwwlogs/access.log;
- error_log /home/wwwlogs/nginx_error.log;
- set $root /home/wwwroot/vaeThink/public;
- location ~ .*\.(gif|jpg|jpeg|bmp|PNG|ico|txt|JS|CSS)$
- {
- root $root;
- }
- location / {
- root $root;
- index index.html index.PHP;
- if ( -f $request_filename) {
- break;
- }
- if ( !-e $request_filename) {
- rewrite ^(.*)$ /index.PHP/$1 last;
- break;
- }
- }
- location ~ .+\.PHP($|/) {
- set $script $uri;
- set $path_info "";
- if ($uri ~ "^(.+\.php)(/.+)") {
- set $script $1;
- set $path_info $2;
- }
- fastcgi_pass unix:/tmp/PHP-CGI.sock;
- fastcgi_index index.PHP?IF_REWRITE=1;
- fastcgi_param PATH_INFO $path_info;
- fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
- fastcgi_param SCRIPT_NAME $script;
- include fastcgi_params;
- }
- }
作者: 一生悬命 Cat
链接: https://www.jianshu.com/p/30048bfe83d2
来源: http://www.bubuko.com/infodetail-3105569.html