502 Bad Gateway with DigitalOcean/Django?

This is my second time setting up a server and I had this same problem last time, but I'm still too much a noob to fix it. Everytime I go to my ip address the website works fine, but whenever I use the domain name it gives me a 502 Bad Gateway. This is my error message:

"2017/03/10 15:12:03 [error] 1652#1652: *30 upstream prematurely closed connection while reading response header from upstream, client: 173.174.110.165, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://unix:/home/django/gunicorn.socket:/favicon.ico", host: "domain_name", referrer: "domain_name"

So the domain is obviously working because I'm getting logs when I use it, but it just gives me a 502. My allowed_host says this: ALLOWED_HOSTS = [domain_name, ip_address]. Is this a Django problem or will I have more luck posting in the sysadmin subreddit?

Posted Mar 10, 2017, 3:20 PM UTC · edited

16
Relaxified•

Try going into your settings.py and, if at the bottom, there's the ALLOWED_HOSTS = ip_addresses() you can comment it out or add a + to include it in the hosts (ALLOWED_HOSTS += ip_addresses())

3
Relaxified•

That was an issue I had when I used the 1-click django from DO.

3
TheStyleGodOP•

YOU DA BEST! Thanks! This fixed it. I will be forever greatful.

1

What is your HTTP server: Nginx? Apache?

What's going on is your HTTP server is trying to pass a request to your wsgi server (gunicorn serving your Django site), and 502 means that connection couldn't be made.

I'd guess your nginx configuration for the domain name is incorrect.

1
TheStyleGodOP•

nginx, i'll look into my config some more.

1
deeds4life•

I just had this issue. Check allowed hosts in your settings.py file. Also make sure uwsgi is running and configured properly. I used this guide to help me out. Digital Ocean Guide

1