简体   繁体   中英

502 Bad Gateway (nginx/1.10.3 (Ubuntu))

i sent my python3 django files to digital ocean server and getting 502 bad gateway error. I tried all the tips given elsewhere in stackoverflow but none worked. I believe there is something wrong with my settings.py. Specifically below lines, please let me know your suggestions:

ALLOWED_HOSTS = ['*']

# Find out what the IP addresses are at run time
# This is necessary because otherwise Gunicorn will reject the connections
def ip_addresses():
    ip_list = []
    for interface in netifaces.interfaces():
        addrs = netifaces.ifaddresses(interface)
        for x in (netifaces.AF_INET, netifaces.AF_INET6):
            if x in addrs:
                ip_list.append(addrs[x][0]['addr'])
    return ip_list

# Discover our IP address
ALLOWED_HOSTS += ip_addresses() 

Bad Gateway error sometimes comes even when there is an error in codes. It can be due to python version. Digital ocean uses 2.7, not 3.6. You have to upgrade Django to 1.11. Make sure your directories inside \\home\\django_project\\django_project are all well.

  1. After all this in the ubuntu console by running python manage.py runserver like we used to do in local environment debug your errors. Don't look anywhere else, this is the best way and will work surely. I wasted 4 days in same error when I switched to production.

Good morning,

My solution in settings.py was:

ALLOWEDHOSTS = ['domainname', 'droplet_IP']

and add the bottom of settings.py

change:

ALLOWEDHOSTS = ipaddresses()

to

ALLOWEDHOSTS += ipaddresses()

Works in Feb '18.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM