[英]502 Bad Gateway (nginx/1.10.3 (Ubuntu))
我將python3 django文件發送到了數字海洋服務器,並收到502錯誤的網關錯誤。 我嘗試了stackoverflow中其他地方給出的所有技巧,但沒有一個起作用。 我相信我的settings.py有問題。 特別是以下幾行,請讓我知道您的建議:
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()
即使代碼中有錯誤,有時也會出現錯誤的網關錯誤。 可能是由於python版本。 數字海洋使用2.7,而不是3.6。 您必須將Django升級到1.11。 確保\\ home \\ django_project \\ django_project內的目錄都正確。
早上好,
我在settings.py中的解決方案是:
ALLOWEDHOSTS = ['domainname', 'droplet_IP']
並添加settings.py的底部
更改:
ALLOWEDHOSTS = ipaddresses()
至
ALLOWEDHOSTS += ipaddresses()
作品將於18年2月發布。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.