简体   繁体   中英

Django - Gunicorn/Nginx - 502 Bad Gateway

Need Help on 502 Bad Gateway ngnix/1.10.3

I have configured my Django application using Nginx/Gunicorn. It was running fine until I made some changes to the code and reloaded the server.

FYI: My settings.py has ALLOWED_HOSTS = ['*']

在此处输入图片说明

Error Logs :

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"

Update 1 :

This is my nginx config. Is there any issue with this?

/etc/nginx/sites-available/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;
    }
}

How do i verify nginx daemon permission to the project folder (//unix://home/ubuntu/www/MySite)

Try manually setting the proxy pass URL to the port gunicorn is running the project on the server like:

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;
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM