502 Bad Gateway Ngnix & Gunicorn

Posted January 20, 2014 78.1k views
Hey guys, I followed these: intrstuctions to get my Django project up and running on my Droplet. Problem is I'm getting a 502 Bad Gateway Error for some strange reason. Has anyone stumbled upon the same issue? All help is appreciated. Thanks!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
13 answers

Anything on this error? It's cropping up all over.
You can pass --log-file to gunicorn when you launch it to specify where the log file gets stored. Any output there would be helpful in figuring this out.

In your file have you set DEBUG to False? If so, remember that you need to add your IP to ALLOWED_HOSTS.

I had a similar problem (502) after creating a new folder as an alternative to the out-of-the-box django_project.

I saw in /var/log/upstart/gunicorn.log that it was getting a permission error on /home/django.

I fixed it by …

$ cd /home
$ chown -R django:django django
Check Gunicorn's error logs, what do you see?
Hi Kamal,

I have the same issue and the log says:

2014/03/06 21:42:23 [error] 2472#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client:, server:, request: "GET / HTTP/1.1", upstream: "", host: ""

I don't have a domain. I use the droplet's ip.

Can you help me? Thanks in advance.
@jbkunst: That means nginx is trying to proxy traffic to port 8001 but there's nothing listening on that port. Is Gunicorn running?
Also having the same problem, Ismail. Any luck figuring it out?
@kpennel: Is Gunicorn running?
sudo netstat -plutn | grep -i unicorn

sudo ps wwaux | grep grep -i unicorn
From the tutorial you mentioned and after configuring nginx, you should change your Gunicorn configuration bind variable to bind='' (not your domain or ip address) as it is nginx the one who handle the requests.
I was having the same issue after following these instructions and I found my way to this page.

After trying tomas.caslo90's suggestion I ended up with a Bad Request (400) instead of a 502 Bad Gateway.

should gunicorn bind to or to

any suggestions for further troubleshooting on this issue. i have followed the instructions in the above article very carefully. gunicorn is definitely running.

I don't know how to access gunicorn's error logs and I'm guessing that might help me greatly.

Thanks very much
by Stephen Tippets
This tutorial runs through both installing and configuring Django with Postgres, Nginx, and Gunicorn on your VPS.
Previous 1 2 Next