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

其他回答

简单但有效。

listen.owner = nginx
listen.group = nginx

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

除了在你的php配置中扩大权限,你可以改变你的nginx配置中指定的用户。

在上面的nginx.conf摘录的第一行,用户和组分别被指定为www和www。

user  www www;

同时,你的php配置可能会指定一个用户和一组www-data:

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

你可以将nginx.conf中的这一行更改为以下任何一行:

user www-data www;
user www-data www-data; # or any group, really, since you have the user matching
user www www-data; # requires that your php listen.mode gives rw access to the group

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

# getenforce

关掉它:

# setenforce 0

@Xander的解决方案工作,但不坚持后重启。

我发现我必须改变听。Mode到“/etc/php5/fpm/pool.d/www.conf”中的0660。

样本来自www.conf:

; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions. 
; Default Values: user and group are set as the running user
;                 mode is set to 0660
;listen.owner = www-data
;listen.group = www-data
;listen.mode = 0660

编辑:根据@Chris Burgess,我已经将此更改为更安全的方法。

我删除了这条评论。模式,.group和.owner:

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

/var/run仅保存上次引导后运行的系统信息,例如当前登录的用户和正在运行的守护进程。(http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard # Directory_structure)。

注:

我的php5-fpm -v报告:PHP 5.4.28-1+deb.sury.org~精确+1。在最近的一次更新之后,这个问题也发生了。

如果你已经尝试了这篇文章中的所有内容,但都没有成功地让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。应该能行。