Transferred from: https://www.centos.bz/2017/07/nginx-php-fpm-502-error/
In the ubuntu+nginx+php environment after deployment, visit the site error 502, in the background Nginx error_log see the following error message (Nginx log path:/var/log/nginx)
2017/07/29 10:59:15 [ERROR] 5622#0: * Connect () failed (111:connection refused) while connecting to Upstrea M, client:183.14.134.39, server:xx.xx.xx.xx, Request: "Get/index.php http/1.1", Upstream: "fastcgi://127.0.0.1:9001", Host: "Xx.xx.xx.xx"
Usually this error indicates that PHP-FPM This service is not started, because the default is configured for Port 9000, execution Netstat-anp|grep 9000 does not see the related process.
But execute command query PHP-FPM is running state
#/etc/init.d/php7.0-fpm StatusPhp7.0-fpm.service–the PHP 7.0FastCGI Process managerloaded: Loaded (/lib/systemd/system/php7.0-fpm.service; Enabled Vendor Preset:enabled) Active: Active (running) since Sat 2017-07-29 11:52:47 CST; 3h 43minagoprocess: 7191 execstartpre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS) Main PID: 7200 (php-fpm7.0) Status: "Processes active:0, Idle:2, requests:54, slow:0, traffic:0req/sec "CGroup: /system. slice/php7.0-fpm.service├─7200 Php-fpm:master Process (/etc/php/7.0/fpm/php-fpm.conf) ├─7203 PHP-FPM:Pool www└─7204 PHP-FPM:Pool Wwwjul11:52:47 Izwz96f0gkw4blayus6g2yz Systemd[1]: Starting the PHP 7.0FastCGI Process Manager ... Jul11:52:47 Izwz96f0gkw4blayus6g2yz systemd[1]: Started the PHP 7.0 FastCGI Process Manager.
View/etc/php/7.0/fpm/pool.d/www.conf and/etc/php/7.0/fpm/php-fpm.conf discover the following parameters:
Listen =/run/php/php7.0-fpm.sock
Check the data only to know that the original PHP-FPM support network port monitoring and socket two ways, but the latter more efficient.
The solution to this problem is to modify the Conf file under Nginx/conf/vhosts,
The Fastcgi_pass 127.0.0.1:9000 is changed to Fastcgi_pass Unix:/run/php/php7.0-fpm.sock;
After restarting Nginx service, Web Access still error 502, continue to locate the analysis.
In the Nginx error_log log, the following new error content appears:
2017/07/29 11:24:47 [Crit] 6114#0: * Connect () to Unix:/run/php/php7.0-fpm.sock failed (13:permission Deni ed) while connecting to upstream, client:183.14.134.xx, server:112.74.89.xx, Request: "get/http/1.1", Upstream: "FASTC Gi://unix:/run/php/php7.0-fpm.sock: ", Host:" 112.74.89.xx "
Then locate the/etc/php/7.0/fpm/pool.d/www.conf file and do the following:
Comment out
; listen.owner = www-data;listen. Group = Www-data
Change the mode value to 0666
Listen.mode = 0666
Finally, perform/etc/init.d/php7.0-fpm restart restart PHP-FPM service, perform/etc/init.d/nginx restart restart Nginx service, problem solving!!!
"Go" resolves 502 errors caused by incorrect nginx PHP-FPM configuration