简体   繁体   English

502错误的网关(nginx / 1.10.3(Ubuntu))

[英]502 Bad Gateway (nginx/1.10.3 (Ubuntu))

i sent my python3 django files to digital ocean server and getting 502 bad gateway error. 我将python3 django文件发送到了数字海洋服务器,并收到502错误的网关错误。 I tried all the tips given elsewhere in stackoverflow but none worked. 我尝试了stackoverflow中其他地方给出的所有技巧,但没有一个起作用。 I believe there is something wrong with my settings.py. 我相信我的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. 可能是由于python版本。 Digital ocean uses 2.7, not 3.6. 数字海洋使用2.7,而不是3.6。 You have to upgrade Django to 1.11. 您必须将Django升级到1.11。 Make sure your directories inside \\home\\django_project\\django_project are all well. 确保\\ home \\ django_project \\ django_project内的目录都正确。

  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. 通过在ubuntu控制台中运行python manage.py runserver之后,像我们以前在本地环境中所做的那样,调试所有错误。 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. 切换到生产环境时,我在相同的错误上浪费了4天。

Good morning, 早上好,

My solution in settings.py was: 我在settings.py中的解决方案是:

ALLOWEDHOSTS = ['domainname', 'droplet_IP']

and add the bottom of settings.py 并添加settings.py的底部

change: 更改:

ALLOWEDHOSTS = ipaddresses()

to

ALLOWEDHOSTS += ipaddresses()

Works in Feb '18. 作品将于18年2月发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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