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

其他回答

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

我确实在我的服务器上更换了好几次操作系统,试图获得最舒适的系统。

它曾经工作得很好,大部分时间,但最后我得到了这个502网关错误。

我为每个帐户使用一个php fpm套接字,而不是为所有帐户保留同一个套接字。因此,如果一个应用程序崩溃,至少其他应用程序可以继续运行。

我以前有用户和组www-data。但这在我的Debian 8上发生了变化,使用了最新的Nginx 1.8和php5-fpm。

默认用户为nginx,组为nginx。为了确保这一点,最好的方法是检查/etc/group和/etc/passwd文件。这些是不会说谎的。

它是在那里,我发现现在我有nginx在两者和不再www-data。

也许这可以帮助那些仍然试图找出错误消息不断出现的原因的人。

这对我很管用。

我今天更新了我的机器(更新了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;

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

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

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

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

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

请注意(至少在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

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