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

当前回答

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

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

其他回答

如果有的话,还必须考虑到您的个人FPM池。

我不明白为什么今天这些答案都对我不起作用。对我来说,这是一个设定后就忘记的场景,我已经忘记了倾听。用户和监听。组在每个池的基础上进行复制。

如果您像我一样为不同的用户帐户使用池,其中每个用户帐户拥有他们的FPM进程和套接字,只设置默认监听。拥有并倾听。“nginx”的组配置选项将根本不起作用。显然,让“nginx”拥有它们也是不可接受的。

对于每个池,请确保

listen.group = nginx

否则,您可以不考虑池的所有权等。

如果每个用户有不同的池,请确保在配置文件中正确设置用户和组。nginx用户可以在/etc/nginx/nginx.conf文件中找到。Nginx组与Nginx用户相同。

user = [pool-user]
group = [pool-group]
listen.owner = [nginx-user]
listen.group = [nginx-group]

-还检查linux (/etc/ SELINUX):

# getenforce

关掉它:

# setenforce 0

我今天更新了我的机器(更新了PHP),运行Ubuntu 14.04,再次得到这个错误。分发配置文件/etc/php5/fpm/pool.d/www.conf很好,目前不需要任何更改。

我发现以下错误:

dmesg | grep php
[...]
[ 4996.801789] traps: php5-fpm[23231] general protection ip:6c60d1 sp:7fff3f8c68f0 error:0 in php5-fpm[400000+800000]
[ 6788.335355] traps: php5-fpm[9069] general protection ip:6c5d81 sp:7fff98dd9a00 error:0 in php5-fpm[400000+7ff000]

奇怪的是,我在这台机器上运行了两个使用PHP-FPM的网站,其中一个运行正常,另一个(一个Tiny Tiny RSS安装)给了我一个502,这两个网站之前都运行正常。

我比较了这两个配置文件,发现fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;受影响的站点缺失。

两个配置文件现在都包含以下块,并再次正常运行:

location ~ \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include /etc/nginx/snippets/fastcgi-php.conf;
}

更新

值得注意的是,Ubuntu提供了两个fastcgi相关的参数文件和一个配置片段,这是在Vivid和PPA版本中提供的。相应更新了解决方案。

fastcgi参数文件的Diff:

$ diff -up fastcgi_params fastcgi.conf
--- fastcgi_params      2015-07-22 01:42:39.000000000 +0200
+++ fastcgi.conf        2015-07-22 01:42:39.000000000 +0200
@@ -1,4 +1,5 @@

+fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
 fastcgi_param  QUERY_STRING       $query_string;
 fastcgi_param  REQUEST_METHOD     $request_method;
 fastcgi_param  CONTENT_TYPE       $content_type;

/etc/nginx/snippets/fastcgi-php.conf中的配置片段

# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;

# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;

# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

fastcgi_index index.php;
include fastcgi.conf;

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

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

修改:用户nginx;

收件人:用户www-data;

然后重启Nginx: service Nginx restart