代码之家  ›  专栏  ›  技术社区  ›  fixgoats

Wagtail忽略设置,例如ALLOWED_HOSTS

  •  1
  • fixgoats  · 技术社区  · 7 年前

    我在Ubuntu 16.04上运行nginx、gunicorn和wagtail。我没有使用virtualenv。nginx和gunicorn似乎都工作得很好,但当我在浏览器(比如myweb.com)中进入我的域时,我得到了一个不允许的主机错误。

    编辑:具体的错误消息是(使用myweb.com而不是实际的域):

    DisallowedHost at /
    
    Invalid HTTP_HOST header: 'myweb.com'. You may need to add 'myweb.com' to ALLOWED_HOSTS.
    
    Request Method:     GET
    
    Request URL:    http://myweb.com/
    
    Django Version:     1.11.5
    
    Exception Type:     DisallowedHost
    
    Exception Value:    Invalid HTTP_HOST header: 'myweb.com'. You may need to add 'myweb.com' to ALLOWED_HOSTS.
    
    Exception Location:     /usr/local/lib/python3.5/dist-packages/django/http/request.py in get_host, line 113
    
    Python Executable:  /usr/bin/python3
    
    Python Version:     3.5.2
    
    Python Path:    
    
    ['/home/fixgoats/myweb-root',
    '/usr/local/bin',
    '/usr/lib/python35.zip',
    '/usr/lib/python3.5',
    '/usr/lib/python3.5/plat-x86_64-linux-gnu',
    '/usr/lib/python3.5/lib-dynload',
    '/usr/local/lib/python3.5/dist-packages',
    '/usr/lib/python3/dist-packages']
    
    Traceback:
    File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py" in inner
    41.             response = get_response(request)
    
    File "/usr/local/lib/python3.5/dist-packages/django/utils/deprecation.py" in __call__
    138.             response = self.process_request(request)
    
    File "/usr/local/lib/python3.5/dist-packages/django/middleware/common.py" in process_request
    57.         host = request.get_host()
    File "/usr/local/lib/python3.5/dist-packages/django/http/request.py" in get_host
    113.             raise DisallowedHost(msg)
    
    Exception Type: DisallowedHost at /
    Exception Value: Invalid HTTP_HOST header: 'myweb.com'. You may need to add 'myweb.com' to ALLOWED_HOSTS.
    
    Request Information:
    
    USER [unable to retrieve the current user]
    
    GET     No GET data
    
    POST    No POST data
    
    FILES   No FILES data
    
    Settings     Using settings module myweb.settings.dev
    
    ALLOWED_HOSTS 'myweb.com'
    

    页面上有更多的信息,但我认为这就是所有可能与问题相关的信息

    1 回复  |  直到 7 年前
        1
  •  1
  •   fixgoats    7 年前

    Gunicorn需要重启。我不知道它是否应该像这样工作,但在我的设置中,似乎总是需要重新启动Gunicorn来检测对项目文件所做的更改。