Reputation: 665
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)
Upvotes: 1
Views: 2065
Reputation: 13
Yes, there is a config issue
location / {
include proxy_params;
proxy_pass http://unix:/home/ubuntu/www/MySite/MySite.sock;
}
/etc/init.d/nginx restart
use below command to check on the permission of socket file
ls -l /home/ubuntu/www/MySite/MySite.sock
Upvotes: 0
Reputation: 105
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;
}
Upvotes: 1