How do I fix error 1078#0? Bad Gateway nginx/1.4.6 (Ubuntu)?

Posted July 11, 2017 6.7k views
NginxDjangoPython FrameworksUbuntu 16.04

Hello guys and girls,

I am getting an error 1078#0 while trying to get my website up and going. Let me give you a chronology of events plus an error log:

I first brought Putty up and went to access my server. I got the Django “It Worked!” message.

After that I went to upgrade my Django and it updated to 1.11. i ran, in the Putty command, “service gunicorn restart”.

Got 502 Bad Gateway

I unistalled Django and was back to version 1.6.1. Refreshed. “Internal Server Error”

So i “pip install django==1.9” and checked version to ensure i was running Django 1.9. “service gunicorn restart”. Restarted. Refreshed. 502 Bad Gateway Error nginx/1.4.6 (Ubuntu).

Here are the errors I am getting when I run “tail -f /var/log/nginx/error.log”: [error] 1078#0: *263 connect() failed (111: Connection refused) while connecting to upstream, client: XX.XXX.XXX.XX, server: _, request: “GET / HTTP/1.1”, upstream: “”, host: “XXX.XXX.X.XX”

Can someone please tell me what is going on here and why? It is very frustrating and getting this website up is mission critical as I have just filed my company and am ready to begin operation.

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 @dayscue

We need the error log from Gunicorn, since that’s the service not running - Nginx only return the default 502 Bad Gateway, since it cannot connect to anything.
It’s normally located in /var/log/upstart/gunicorn.log but you might run it with a different job name and then you have to look for /var/log/upstart/$JOB_NAME.log.

EDIT: But if you don’t see any logs, then you might need to update your Gunicorn script to include the --error-logfile /path/to/log/file:

But since you haven’t used the server yet, then you could just rebuild it (you will lose all data on the server) back to the Django One-Click.
If you want to rebuild, go to the DigitalOcean control panel, click the droplet, click the Destroy menu on the left, search for “Django”, select the image and click Rebuild.

  • Okay so how do I do what you just told me? K-12 it for me if you can. where would /var/log/upstart/gunicorn be located? and then you say i might need to update gunicorn script. how do i go about this all?

    • @dayscue

      tail -30 /var/log/upstart/gunicorn.log

      If you don’t know how to get around in Linux, then I would probably recommend that you just rebuild the server with a One-Click App (which is almost the same as deleting it and creating a new).