我将nginx更新到1.4.7,将php更新到5.5.12,之后我得到了502错误。在我更新之前,一切都很好。
nginx-error.log
2014/05/03 13:27:41 [crit] 4202#0: *1 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: xx.xxx.xx.xx, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "xx.xx.xx.xx"
nginx.conf
user www www;
worker_processes 1;
location / {
root /usr/home/user/public_html;
index index.php index.html index.htm;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/home/user/public_html$fastcgi_script_name;
include fastcgi_params;
}
这里最重要的事情是,如果用户正在使用nginx,那么你也需要指定它
在nginx.conf中
user www-data;
worker_processes 1;
location / {
root /usr/home/user/public_html;
index index.php index.html index.htm;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/home/user/public_html$fastcgi_script_name;
include fastcgi_params;
}
在你的www.conf
listen.owner = www-data
listen.group = www-data
;listen.mode = 0660
在你的例子中,用户和组是“www”,所以只需替换它。
重启nginx和PHP FPM
我通过以下步骤修复了亚马逊Linux AMI 2016.09 (Centos 7)上的相同问题。
打开www.conf文件(例如:sudo nano /etc/php-fpm.d/www.conf)
最后,找到设置监听的语句。拥有并倾听。将它们的值从“nobody”改为“nginx”:
listen.owner = nginx
listen.group = nginx
listen.mode = 0666
最后,找到设置用户和组的行,并将它们的值从"apache"改为"nginx":
user = nginx
group = nginx
重启php-fpm (sudo service)
下面的简单修复对我有用,绕过了套接字可能的权限问题。
在你的nginx配置中,设置fastcgi_pass为:
fastcgi_pass 127.0.0.1:9000;
而不是
fastcgi_pass /var/run/php5-fpm.sock;
这必须匹配/etc/php5/fpm/pool.d/www.conf中的listen =参数,所以也将其设置为:
listen = 127.0.0.1:9000;
然后重新启动php5-fpm和nginx
service php5-fpm restart
And
service nginx restart
更多信息,请参见:https://wildlyinaccurate.com/solving-502-bad-gateway-with-nginx-php-fpm/