Django and Nginx: 502 error

April 19, 2014 6k views
Hello :) While trying to deploy my app to Digital ocean I did everything according to this tutorial: https://www.digitalocean.com/community/articles/how-to-deploy-a-local-django-app-to-a-vps. While Gunicorn is working perfectly and http://95.85.34.87:8001/ opens my app, Nginx, however, does not work, http://95.85.34.87 or http://95.85.34.87/static causes a 502 error. Nginx log says, that : 2014/04/19 02:43:52 [error] 896#0: *62 connect() failed (111: Connection refused) while connecting to upstream, client: 78.62.163.9, server: 95.85.34.87, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8001/", host: "95.85.34.87" My nginx configuration file looks like this: server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; server_name 95.85.34.87; access_log off; location /static/ { alias /opt/myenv/static/; } location / { proxy_pass http://127.0.0.1:8001; proxy_set_header X-Forwarded-Host $server_name; proxy_set_header X-Real-IP $remote_addr; add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"'; } In Django.settings I have ALLOWED_HOSTS setting set to '[*]'
1 Answer
I changed the proxy_pass http://127.0.0.1:8001; line under location / to my servers IP address (instead of loccalhost) and everything worked. I am not sure if it's good decission or not.
  • I had the same problem, and this works!!! Thanks a million

  • You just saved my life !! thank you soooooo much. Can't tell you how many times I was looking for this answer. OMG Thanks again !

Have another answer? Share your knowledge.