繁体   English   中英

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

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

  1. 通过在ubuntu控制台中运行python manage.py runserver之后,像我们以前在本地环境中所做的那样,调试所有错误。 别看其他地方,这是最好的方法,一定可以正常工作。 切换到生产环境时,我在相同的错误上浪费了4天。

早上好,

我在settings.py中的解决方案是:

ALLOWEDHOSTS = ['domainname', 'droplet_IP']

并添加settings.py的底部

更改:

ALLOWEDHOSTS = ipaddresses()

ALLOWEDHOSTS += ipaddresses()

作品将于18年2月发布。

暂无
暂无

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

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