surroundings
OS: Ubuntu 19.04
nginx version: nginx / 1.16.0
Test error 502 Bad Gateway php
Direct access localhost
is not a problem, because the direct resolution is a static document index.html
:
Remove the default working directory index.html
, the new php test file sudo vi /usr/share/nginx/html/index.php
:
<?php phpinfo(); ?>
Unable to resolve PHP, what happens! ?
The reason given
At this time we can guess the problem php-fpm, but what's the problem then? The reason is that in php-fpm default configuration listen = /run/php/php7.2-fpm.sock
, but sometimes under unix socket mode will lead to 502, I am here to lay the shot!
Solution
Php-fpm modified configuration, the mode change unix socket tcp / ip manner. sudo vi /etc/php/7.2/fpm/pool.d/www.conf
:
;listen = /run/php/php7.2-fpm.sock #给老子滚犊子
listen = 127.0.0.1:9000
Synchronization modify nginx conf sudo vi /etc/nginx/conf.d/server.conf
file :
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/run/php/php7.2-fpm.sock; 给老子滚犊子
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
All normal