[英]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内的目录都正确。
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.