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

当前回答

如果你有声明

Pid = /run/php-fpm.pid

and

Listen = /run/php-fpm.pid

在不同的配置文件中,root将是该文件的所有者。

其他回答

在这里:

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

但这里也要改变:

; When set, listen.owner and listen.group are ignored
listen.acl_users = apache
;listen.acl_groups =

注释这一行:

; When set, listen.owner and listen.group are ignored
;listen.acl_users = apache
;listen.acl_groups =

简单但有效。

listen.owner = nginx
listen.group = nginx

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

如果每个用户有不同的池,请确保在配置文件中正确设置用户和组。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

@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。在最近的一次更新之后,这个问题也发生了。