2017-06-04 26 views
1

我有一个地址说example.com并已将其添加到allowed_hosts列表中。但是当我访问该网站时,我得到 ALLOWED_HOSTS ['127.0.0.1', '::1', '178.XX.XX.XXX', 'xx80::xx81:xxx:xx3x:x12x%eth0']allowed_host更改无效

在调试错误页面,而实际的settings.py文件读取['178.XX.XX.XXX','example.com']。我想到settings.py的更改没有注册,因为我可以从列表中删除178.XX.XX.XXX,并仍然访问该站点(清除浏览器缓存后)我重新启动了nginx,gunicorn和整个服务器都无济于事。整个事情是在Ubuntu 16.04上运行django 1.8并使用nginx和gunicorn。任何想法allowed_hosts这个覆盖可能来自?

+0

也许尝试删除项目树中的所有* .pyc调用? – FlipperPA

+0

除了删除* .pyc文件,检查以确保gunicorn路径是正确的,并指向正确的应用程序。 –

回答

2

好的,这是令人尴尬的,但是从Digital Ocean在16.04上的django的One-cick安装在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() 
ALLOWED_HOSTS.append('.example.com') #I added this line 

因此,为该行添加追加可修复该问题。