一切都运行正常,直到我将 PHP 更新到 7.2
服务器重启后一分钟内 nginx 抛出 502 错误。
Nginx 错误日志指出如果监听unix:/var/run/php/php7.2-fpm.sock
:
[crit] 671#671: *2 connect() to unix:/var/run/php/php7.2-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 123.123.123.123, server: mysite.domain, request: "POST /provider.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock:", host: "mysite.domain", referrer: "http://mysite.domain/"
并说
[error] 667#667: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 123.123.123.123, server: mysite.domain, request: "POST /provider.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mysite.domain", referrer: "http://mysite.domain/"
如果听127.0.0.1:9000
无论如何,一分钟后 nginx 开始按预期工作。
好像 php7.2-fpm 启动太慢了。
有人知道发生了什么事吗?服务应该在几秒内重启,而不是几分钟。
答案1
我想并执行了您的网站,页面显示了 502 bad gateway 消息。这对我有帮助:
- Edit /etc/php5/fpm/pool.d/www.conf
- Change listen = /var/run/php5-fpm.sock to listen = 127.0.0.1:9000
- Ensure the location is set properly in nginx.conf.
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
- Run sudo service php5-fpm restart
所以也许它会对你有帮助。
链接来源:https://wildlyinaccurate.com/solving-502-bad-gateway-with-nginx-php-fpm/