Nginx 错误 111,网站给出 502 错误网关

Nginx 错误 111,网站给出 502 错误网关

我正在使用 Django、Nginx 和 Gunicorn 构建一个网站。几个月来一切都运行良好,直到今天我重新启动 nginx 服务后,我的网站出现 502 错误网关。

root@xxx:/# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

这是错误日志(我的网站正在生产中):

root@xxx:/# cat /var/log/nginx/error.log

2019/06/05 11:53:44 [error] 1577#1577: *3 connect() to unix:/home/xxx/xxx/xxx.sock failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.net, request: "GET / HTTP/1.1", upstream: "http://unix:/xxx/xxx/xxx/xxx.sock:/", host: "xxx.net"

这是配置:

root@vps675614:/# cat /etc/nginx/sites-enabled/xxx 
server {
    server_name xxx.net;

    location = /favicon.ico { access_log off; log_not_found off; }

    location / {
        include proxy_params;
        proxy_pass http://unix:/xxx/xxx/xxx/xxx.sock;
    }

    location /static/ {
       alias /xxx/xxx/xxx/static/;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/xxx.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/xxx.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = xxx.net) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name xxx.net;
    return 404; # managed by Certbot


}

服务器:Ubuntu 18.04 LTS

答案1

基于http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass,unix 套接字的路径必须完全由两个冒号括起来,因此您的proxy_pass行应如下所示:

proxy_pass http://unix:/xxx/xxx/xxx/xxx.sock:/;

相关内容