我将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;
        }

当前回答

查看/etc/php5/php-fpm.conf即可 Pid = /var/run/php5-fpm.pid IS pid文件

在/etc/php5/fpm/pool.d/www.conf文件中

监听= /var/run/php5-fpm.SOCKET文件

如果你pid等于监听(pid = /var/run/php5-fpm. .Sock和listen = /var/run/php5-fpm.sock) ->错误设置 设置/etc/php5/fpm/pool.d/www.conf

user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

其他回答

这里目前提到的所有修复程序基本上都重新启用了安全漏洞。

我最后做的是将以下几行代码添加到我的PHP-FPM配置文件。

listen.owner = www-data
listen.group = www-data

确保www-data是nginx worker实际运行的用户。对于debian,默认是www-data。

这样做并不会启用此更改应该修复的安全问题。

我有一个类似的错误后,php更新。PHP修正了o对套接字文件具有rw权限的安全错误。

打开/etc/php5/fpm/池.d/www.conf或/etc/php/7.0/fpm/池.d/www.conf,具体取决于您的版本。 取消所有权限行注释,例如: 听。Owner = www-data 听。Group = www-data 听。模式= 0660 重启fpm - sudo service php5-fpm Restart或sudo service php7.0-fpm Restart

注意:如果你的服务器不是以www-data用户运行,你需要相应地更新www.conf文件

在我的案例中,问题是Nginx web服务器以用户Nginx运行,而池以用户www-data运行。

我通过改变用户Nginx在/etc/nginx/nginx.conf文件中运行的问题解决了这个问题(可能在你的系统上不同,我的是Ubuntu 16.04.1)

修改:用户nginx;

收件人:用户www-data;

然后重启Nginx: service Nginx restart

下面的简单修复对我有用,绕过了套接字可能的权限问题。

在你的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/

在这里:

user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

但这里也要改变:

; When set, listen.owner and listen.group are ignored
listen.acl_users = apache
;listen.acl_groups =

注释这一行:

; When set, listen.owner and listen.group are ignored
;listen.acl_users = apache
;listen.acl_groups =