這些線程有幾個,但它們都不能解決我的問題。我有一個服務器託管一個網站,如果你通過IP地址直接通過網站工作,但是我買了一個DNS,我試圖將DNS重定向到IP。我正在使用django 1.11.4(當前的pip安裝版本)。設置了我所有的DNS服務器後,我可以ping服務器,但如果我去我的DNS一個瀏覽器,鍵入我收到此錯誤:Django/Nginx DisallowedHost標題錯誤
Environment:
Request Method: GET
Request URL: http://thefelpub.com/
Django Version: 1.11.4
Python Version: 2.7.12
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pub')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in _legacy_get_response
244. response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in process_request
57. host = request.get_host()
File "/usr/local/lib/python2.7/dist-packages/django/http/request.py" in get_host
113. raise DisallowedHost(msg)
Exception Type: DisallowedHost at/
Exception Value: Invalid HTTP_HOST header: 'thefelpub.com'. You may need to add u'thefelpub.com' to ALLOWED_HOSTS.
我已經加入我的DNS到ALLOWED_HOSTS = []列表,但無論我嘗試多少種dns嘗試(包括'*'),每次嘗試到達時都會得到相同的錯誤。
您是否在添加'ALLOWED_HOSTS = ['*']'後重新啓動django? –
是的,我每次嘗試更改ALLOWED_HOSTS後重新啓動nginx – baneofalltrades
重新啓動gunicorn而不是nginx以使更改生效 – deaspo