How do I fix this 502 Bad Gateway error when setting up Django project on Ubuntu 14.04.5 box?
I'm trying to set up WSGI/nginx with a Django project, but am getting a 502 error. Seems like there's a problem finding the .sock
file. Here's more info that should help illustrate my problem. https://serverfault.com/questions/908922/sock-does-not-exist-error-connect-error
Anyone know what I need to fix to get rid of the error so my site displays correctly?
1 Reply
Everything in Unix is a file. Its arguably one of its greatest strengths. This holds true for unix domain sockets. Its why its complaining that it can't find a file.
If I look at your nginx conf…
server {
listen 80;
server_name mydomain.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/django/FOLDER;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/home/django/FOLDER/product_blog/product_blog.sock;
}
}
We see you are using the uwsgi_pass
directive to instruct nginx to forward requests for /
to a unix domain socket. This socket is addressed by a file location.
In your uwsgi config…
[uwsgi]
project = product_blog
base = /home/django
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 2
socket = %(base)/%(project)/%(project).sock
chmod-socket = 664
vacuum = true
Through some substitution you instruct uwsgi
to install a domain socket file at /home/django/product_blog/product_blog.sock
. In order for nginx to connect to that socket there must be a file in the correct location with the correct privileges. When you start uwsgi
it should create the *.sock
file in the specified location.
things to try
- Make sure you are using a valid file path in your
uwsgi.conf
(including the directories) - Start
uwsgi
and make sure your*.sock
file is in the correct location - Make sure the
proxy_pass
directive in nginx is pointing to this file.