502 Bad Gateway Ngnix & Gunicorn

  • Posted January 20, 2014

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.



Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

You can pass <code>–log-file</code> to gunicorn when you launch it to specify where the log file gets stored. Any output there would be helpful in figuring this out. <br> <br>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

I had the same and just had to restart gunicorn with service supervisor restart

Hope that helps.

Hi, when i open the IP address in browser i got this: The requested URL / was not found on this server. however, i can got to admin page but the css is not rendered.


2015/01/26 14:53:35 [error] 5935#0: *2 open() “/bootstrap/js/bootstrap.min.js” failed (2: No such file or directory), client:, server:, request: “GET /static/bootstrap/js/bootstrap.min.js HTTP/1.1”, host: “”, referrer: “” 2015/01/26 14:55:44 [error] 5935#0: *8 open() “/css/hamburger.css” failed (2: No such file or directory), client:, server:, request: “GET /static/css/hamburger.css HTTP/1.1”, host: “”

this is how i run my server: gunicorn -b joyceful.wsgi:application

this is my nginx config file:

server { server_name myIPaddress;

access_log off;

location /static/ {
    alias /home/yshang/joyceful-venv/joycful/static/;

location / {
    proxy_pass http://myIPaddress:8001;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Real-IP $remote_addr;


please help. thanks

I have the same issue as brentlunghino and I would love some additional help.

Hi, <br>I was having the same issue after following these instructions and I found my way to this page. <br> <br>After trying tomas.caslo90’s suggestion I ended up with a Bad Request (400) instead of a 502 Bad Gateway. <br> <br>should gunicorn bind to or to <br> <br>any suggestions for further troubleshooting on this issue. i have followed the instructions in the above article very carefully. gunicorn is definitely running. <br> <br>I don’t know how to access gunicorn’s error logs and I’m guessing that might help me greatly. <br> <br>Thanks very much

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.

@kpennel: Is Gunicorn running? <pre>sudo netstat -plutn | grep -i unicorn <br>sudo ps wwaux | grep grep -i unicorn</pre>

Also having the same problem, Ismail. Any luck figuring it out?

@kamal <br> <br>Anything on this error? It’s cropping up all over.