Rebooted server via ubuntu command line, now website returns 502

March 6, 2019 1.6k views
Django Nginx Python Ubuntu 18.04

Hi,
My website has been running since I deployed it yesterday.
I rebooted the server this morning, and now the website won't load.
Im using nginx and gunicorn - i have tested both and the tests were successful.

What reasons are there that the website now wont load, after nothing was changed during the reboot

1 Answer

502 Bad Gateway means nginx is unable to communicate to gunicorn.

Make sure that gunicorn is running on the expected port. You can verify it using :

netstat -tulpn

If you find it running and the website still shows 502, try restarting nginx and gunicorn.

Let me know if you have any further questions.

  • I can't see gunicorn in the table (posted below), i'm assuming that's the issue? It's strange as when I run sudo systemctl status gunicorn.socket, it says gunicorn is active

    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1849/nginx: master
    tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 718/systemd-resolve
    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 997/sshd
    tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1037/postgres
    tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1849/nginx: master
    tcp6 0 0 :::80 :::* LISTEN 1849/nginx: master
    tcp6 0 0 :::22 :::* LISTEN 997/sshd
    udp 0 0 127.0.0.53:53 0.0.0.0:* 718/systemd-resolve

    • What errors you find with "tail -F /var/log/nginx/error.log"

      Probably there is a problem with the sock file.

Have another answer? Share your knowledge.