Nginx 在访问我的网站时遇到 502 网关错误

时间:2021-01-02 23:50:12

标签: php nginx

我在访问我的网站时不时遇到 502 网关错误。

Ubuntu 20.04, nginx, PHP-FPM 7.4, 虚拟机, Cloudflare

/etc/php/7.4/fpm/pool.d pastebin

/etc/php/7.4/fpm/pool.d pastepin

nginx 错误日志

2021/01/02 17:14:00 [error] 56540#56540: *248074 connect() failed (111: Connection refused) while connecting to upstream, client: 188.114.110.89, server: example.com, request: "POST /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:8000", host: "www.example.com", referrer: "https://www.example.com/"
2021/01/02 17:14:26 [error] 56540#56540: *248088 connect() failed (111: Connection refused) while connecting to upstream, client: 162.158.165.247, server: example.com, request: "POST /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:8000", host: "www.example.com", referrer: "https://www.example.com/index.php"
2021/01/02 17:15:14 [error] 56540#56540: *248098 connect() failed (111: Connection refused) while connecting to upstream, client: 162.158.134.121, server: example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:8000", host: "www.example.com"
2021/01/02 17:15:43 [error] 56540#56540: *248109 connect() failed (111: Connection refused) while connecting to upstream, client: 188.114.110.89, server: example.com, request: "POST /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:8000", host: "www.example.com", referrer: "https://www.example.com/"

php -i 输出

https://pastebin.com/He4vUXwK

1 个答案:

答案 0 :(得分:1)

您的 Nginx 尝试在 127.0.0.1:8000 访问 php,并且您的 php 配置文件提到了 localhost:8000run/php/php7.4-fpm.sock

您应该运行 php -i 来确定您的 php-fpm 服务器在哪个地址上接受 FastCGI 请求(套接字、本地主机或 127.0.0.1)并相应地调整您的配置(配置您的 php 监听参数或您的 nginx fastcgi 地址)。

注意:您的服务器可能没有正确地将 localhost 解析为 127.0.0.1