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端口:
[root@izwz9glf2r6p2z8ytslvblz /]# netstat -ant | grep 9000
发现并没有监听到,但实际上我们的php-fpm已经启动,那现在怎么办呢?
我们去查看一下php-fpm.conf里面的配置:
[root@izwz9glf2r6p2z8ytslvblz /]# 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;
}
}
网友评论