Question

Bad Gateway nginx/1.18.0(Ubuntu)

I edited /etc/systemd/system/gunicorn.service and /etc/nginx/sites-enabled/default and changed django_project to my project name, restarted gunicorn and got the Bad Gateway error. Where do I start to search?


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

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.

Hi there,

It sounds like that the Django service is not running. I could suggest following the steps here on how to troubleshoot common problems with Django:

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04

Mainly try out the following commands:

  • First check the Nginx error log for the exact error why it is returning 502:
tail -100 /var/log/nginx/error.log
  • Check the system logs for the Gunicorn service:
sudo journalctl -u gunicorn

Usually, 502 is returned by Nginx when it fails to connect to the backend service, which indicates that it is either a problem with the Nginx configuration or the backend service is unavailable.

Here is a quick video on how to troubleshoot a 502 error, though it uses Docker as an example:

Regards, Bobby