I have followed https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn tutorial to deploy django app. At the end of it, when i tried accessing I got “502 Bad Gateway”.
Here are nginx error logs from error.logs file.
2017/03/01 06:40:13 [error] 26234#26234: *16 connect() failed (111: Connection refused) while connecting to upstream, client: 85.203.18.254, server: 174.138.68.184, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8001/", host: "174.138.68.184"
2017/03/01 06:41:00 [error] 26301#26301: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 85.203.18.254, server: 174.138.68.184, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8001/", host: "174.138.68.184"
This textbox defaults to using Markdown to format your 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.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
@hansen @jtittle Thanks for clarifying the issue.
Yes gunicorn is running.
Infact i can access django app at http://174.138.68.184:8001/ even when i turn off nginx. That means i guess gunicorn is working as expected.
I also tried to view error logs of gunicorn by specifying --log-file as below:
gunicorn --bind 174.138.68.184:8001 --log-file g.log django_project.wsgi
Here is the content of the log file.
It’s because Gunicorn is not running, so when Nginx cannot connect to the upstream server it gives the error 502. Did you remember to start Gunicorn? It’s in the lower half of step 9.