Nginx 502错误的网关错误

目前在我的Centos 6.8服务器上有一个502错误的网关错误。

2017/01/30 23:57:31 [crit] 26911#0: *1 connect() to unix:/var/run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.0.15, server: 192.168.0.$ 

我检查了目录是否存在,而不是。 我能find的最近的文件夹是/ var / run / php-fpm,它只包含php-fpm.pid。

以下是解决此问题的步骤:

  1. 检查php-fpm是否正在运行:

     sudo service php-fpm status sudo service php7-php-fpm status # use this if you are using remi PHP 7 
  2. 检查php-fpm的www.confconfiguration文件中的listen指令:

     grep -Ri listen /etc/php/7.0/fpm/pool.d/www.conf grep -Ri listen /etc/opt/remi/php70/php-fpm.d # for remi 
  3. 确保你的nginx fastcgi_pass指令与你的listen指令相匹配。

对我来说,安装过程是这样的,从nginx.org回购安装nginx之后:

 mkdir -p /var/www/public_html chown -R nginx:nginx /var/www/public_html restorecon -rv /var/www yum install php-fpm sed -i 's@listen = 127.0.0.1:9000@listen = /var/run/php-fpm/php-fpm.sock@' /etc/php-fpm.d/www.conf sed -i 's@;listen.owner = [email protected] = nobody@' /etc/php-fpm.d/www.conf sed -i 's@;listen.group = [email protected] = nobody@' /etc/php-fpm.d/www.conf sed -i 's@user = apache@user = nginx@' /etc/php-fpm.d/www.conf sed -i 's@group = apache@group = nginx@' /etc/php-fpm.d/www.conf systemctl start php-fpm.service systemctl enable php-fpm.service 

那么你的主机configuration应该是这样的:

 server { listen 443 ssl; root /var/www/public_html; index index.php; location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 

然后重新启动nginx,你去了。