首页 文章

Django - Gunicorn / Nginx - 502 Bad Gateway

提问于
浏览
0

需要帮助502 Bad Gateway ngnix / 1.10.3

我使用Nginx / Gunicorn配置了我的Django应用程序 . 它运行正常,直到我对代码进行了一些更改并重新加载了服务器 .

仅供参考:我的settings.py有ALLOWED_HOSTS = ['*']

enter image description here

错误日志:

2018/06/27 08:36:38 [crit] 7444#7444: *35 connect() to unix://home/ubuntu/www/MySite/MySite.sock failed (13: Permission denied) while connecting to upstream, client: 106.51.16.0, server: 18.191.255.247, request: "GET /report/ HTTP/1.1", upstream: "http://unix://home/ubuntu/www/MySite/MySite.sock:/report/", host: "18.191.255.247"
2018/06/27 08:36:40 [crit] 7444#7444: *35 connect() to unix://home/ubuntu/www/MySite/MySite.sock failed (13: Permission denied) while connecting to upstream, client: 106.51.16.0, server: 18.191.255.247, request: "GET /report/ HTTP/1.1", upstream: "http://unix://home/ubuntu/www/MySite/MySite.sock:/report/", host: "18.191.255.247"
2018/06/27 08:36:41 [crit] 7444#7444: *35 connect() to unix://home/ubuntu/www/MySite/MySite.sock failed (13: Permission denied) while connecting to upstream, client: 106.51.16.0, server: 18.191.255.247, request: "GET /report/ HTTP/1.1", upstream: "http://unix://home/ubuntu/www/MySite/MySite.sock:/report/", host: "18.191.255.247"
2018/06/27 08:39:06 [crit] 7444#7444: *41 connect() to unix://home/ubuntu/www/MySite/MySite.sock failed (13: Permission denied) while connecting to upstream, client: 106.51.16.0, server: 18.191.255.247, request: "GET /report/ HTTP/1.1", upstream: "http://unix://home/ubuntu/www/MySite/MySite.sock:/report/", host: "18.191.255.247"

更新1:

这是我的nginx配置 . 这有什么问题吗?

在/ etc / nginx的/网站可用/ mysite的

server {
    listen 80;
    server_name 18.191.255.247;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/ubuntu/www/MySite;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix://home/ubuntu/www/MySite/MySite.sock;
    }
}

如何验证项目文件夹的nginx守护程序权限(// unix:// home / ubuntu / www / MySite)

2 回答

  • 0

    调试过程:首先,我尝试使用以下命令检查状态是否处于活动状态 . 事实并非如此

    sudo systemctl status gunicorn
    

    后来我尝试重新启动而不是启动gunicorn

    sudo systemctl restart gunicorn
    

    这解决了我的问题

  • 0

    尝试手动将代理传递URL设置为端口gunicorn正在服务器上运行项目,如:

    location / {
                    proxy_pass         http://localhost:8000;
                    proxy_redirect     off;
                    proxy_set_header   Host              $http_host;
                    proxy_set_header   X-Real-IP         $remote_addr;
                    proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
                    proxy_connect_timeout 500;
                    proxy_read_timeout 600;
            }
    

相关问题