我将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,那么你也需要指定它

在nginx.conf中

user www-data;
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;
        }

在你的www.conf

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

在你的例子中,用户和组是“www”,所以只需替换它。

重启nginx和PHP FPM

其他回答

我有一个类似的错误后,php更新。PHP修正了o对套接字文件具有rw权限的安全错误。

打开/etc/php5/fpm/池.d/www.conf或/etc/php/7.0/fpm/池.d/www.conf,具体取决于您的版本。 取消所有权限行注释,例如: 听。Owner = www-data 听。Group = www-data 听。模式= 0660 重启fpm - sudo service php5-fpm Restart或sudo service php7.0-fpm Restart

注意:如果你的服务器不是以www-data用户运行,你需要相应地更新www.conf文件

如果你有声明

Pid = /run/php-fpm.pid

and

Listen = /run/php-fpm.pid

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

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

# getenforce

关掉它:

# setenforce 0

只需添加,在CentOS(可能还有Red Hat和Fedora)上,要更改权限的文件位于:

/etc/php-fpm.d/www.conf

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

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