我将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用户可以在/etc/nginx/nginx.conf文件中找到。Nginx组与Nginx用户相同。

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

其他回答

我也犯过类似的错误。

所有的建议都不起作用。

用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

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

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

事实上,“听”。mode”应该是:“0660”而不是“0666”,因为其他可写或其他可读从来不是一个好的选择。

因此,尝试找出您的web服务器运行的用户/组。我使用CentOs,它以“nginx”用户运行 所以在你的php-fpm.conf中添加:

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

最后重新启动php-fpm

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

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

如果你已经尝试了这篇文章中的所有内容,但都没有成功地让PHP工作,这是为我的案例修复的:

确保在/etc/php5/fpm/pool.d/www.conf中没有注释这些行:

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

确保/etc/nginx/fastcgi_params看起来像这样:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  PATH_INFO          $fastcgi_script_name;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

这两行在我的/etc/nginx/fastcgi_params中丢失了,请确保它们在那里!

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  PATH_INFO          $fastcgi_script_name;

然后重新启动php5-fpm和nginx。应该能行。