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

当前回答

对我来说,在PHP-FPM listen socket define /run/ PHP-FPM / PHP-FPM之前是unix: directive。袜子在www.conf文件 我简单的Nginx配置文件php块是这样的

 location ~ \.php$ {
            root           /home/mysuser/www;
            fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

其他回答

我也犯过类似的错误。

所有的建议都不起作用。

用nginx替换www-data的唯一方法是:

$ sudo chown nginx:nginx /var/run/php/php7.2-fpm.sock

/var/www/php/fpm/pool.d/www.conf

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

查看/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

我想对那些尝试了所有方法但仍然卡住的人说:这解决了我的问题。 我更新了/usr/local/nginx/conf/nginx.conf

取消标注user的行 把它改成www-data,这样它就变成:user www-data; 保存它(需要根权限) 重启nginx

简单但有效。

listen.owner = nginx
listen.group = nginx

chown nginx:nginx /var/run/php-fpm/php-fpm.sock

请注意(至少在8分)你分配的用户在听。所有者和其他东西,它必须 与用户在同一个POOL中,例如我是foo用户

[www] # WRONG | IN MY CASE I WAS UNDER www POOL SO IT WASNT WORKING FOR ME.
[foo] # CORRECT | THE POOL AND THE USER MATCHES.

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

我不知道是否有一个全球性的游泳池,但经过几个小时的搜索,我终于做到了。