Bad Gateway nginx/1.18.0(Ubuntu)

Posted May 6, 2021 1.3k views

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?

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
1 answer

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:

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:


by Justin Ellingwood
Django is a powerful web framework that can help you get your Python application or website off the ground. Django includes a simplified development server for testing your code locally, but for anything even slightly production related, a more secure and powerful web server...