DisallowedHost: Invalid HTTP_HOST header #64

Closed
opened 2025-12-28 23:25:03 +01:00 by adam · 4 comments
Owner

Originally created by @hackdefendr on GitHub (Nov 8, 2025).

This is a brand new fresh installation and the only thing I did different was to put an Nginx reverse proxy in front of the app. DJANGO_ALLOWED_HOSTS is default, but it won't allow me to access and instead throws an HTTP 400 as shown below:

localhost  | [2025-11-08 09:34:56] - ERROR - django.security.DisallowedHost - Invalid HTTP_HOST header: 'finance.knowelltech.net'. You may need to add 'finance.knowelltech.net' to ALLOWED_HOSTS.
localhost  | Traceback (most recent call last):
localhost  |   File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
localhost  |     response = get_response(request)
localhost  |                ^^^^^^^^^^^^^^^^^^^^^
localhost  |   File "/usr/local/lib/python3.11/site-packages/django/utils/deprecation.py", line 119, in __call__
localhost  |     response = self.process_request(request)
localhost  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
localhost  |   File "/usr/local/lib/python3.11/site-packages/django/middleware/common.py", line 48, in process_request
localhost  |     host = request.get_host()
localhost  |            ^^^^^^^^^^^^^^^^^^
localhost  |   File "/usr/local/lib/python3.11/site-packages/django/http/request.py", line 202, in get_host
localhost  |     raise DisallowedHost(msg)
localhost  | django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'finance.knowelltech.net'. You may need to add 'finance.knowelltech.net' to ALLOWED_HOSTS.

I have already tried adding my server's fqdn in my hosts file and on that DJANGO_ALLOWED_HOSTS configuration in .env and still it won't let me access the web frontend.

Can someone please help?

Originally created by @hackdefendr on GitHub (Nov 8, 2025). This is a brand new fresh installation and the only thing I did different was to put an Nginx reverse proxy in front of the app. DJANGO_ALLOWED_HOSTS is default, but it won't allow me to access and instead throws an HTTP 400 as shown below: ``` localhost | [2025-11-08 09:34:56] - ERROR - django.security.DisallowedHost - Invalid HTTP_HOST header: 'finance.knowelltech.net'. You may need to add 'finance.knowelltech.net' to ALLOWED_HOSTS. localhost | Traceback (most recent call last): localhost | File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner localhost | response = get_response(request) localhost | ^^^^^^^^^^^^^^^^^^^^^ localhost | File "/usr/local/lib/python3.11/site-packages/django/utils/deprecation.py", line 119, in __call__ localhost | response = self.process_request(request) localhost | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ localhost | File "/usr/local/lib/python3.11/site-packages/django/middleware/common.py", line 48, in process_request localhost | host = request.get_host() localhost | ^^^^^^^^^^^^^^^^^^ localhost | File "/usr/local/lib/python3.11/site-packages/django/http/request.py", line 202, in get_host localhost | raise DisallowedHost(msg) localhost | django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'finance.knowelltech.net'. You may need to add 'finance.knowelltech.net' to ALLOWED_HOSTS. ``` I have already tried adding my server's fqdn in my hosts file and on that DJANGO_ALLOWED_HOSTS configuration in .env and still it won't let me access the web frontend. Can someone please help?
adam closed this issue 2025-12-28 23:25:03 +01:00
Author
Owner

@eitchtee commented on GitHub (Nov 8, 2025):

Hey there

What does your DJANGO_ALLOWED_HOSTS variable looks like?

It should look something like this:
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] finance.knowelltech.net

@eitchtee commented on GitHub (Nov 8, 2025): Hey there What does your DJANGO_ALLOWED_HOSTS variable looks like? It should look something like this: DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] finance.knowelltech.net
Author
Owner

@eitchtee commented on GitHub (Nov 8, 2025):

Also, are you using HTTPS? If not, you may want to set HTTPS_ENABLED to false

@eitchtee commented on GitHub (Nov 8, 2025): Also, are you using HTTPS? If not, you may want to set HTTPS_ENABLED to false
Author
Owner

@hackdefendr commented on GitHub (Nov 8, 2025):

localhost 127.0.0.1 [::1] finance.knowelltech.net

That was it. Order of operation. I had my hostname first and never tried it like you showed.

Thanks!!

@hackdefendr commented on GitHub (Nov 8, 2025): > localhost 127.0.0.1 [::1] finance.knowelltech.net That was it. Order of operation. I had my hostname first and never tried it like you showed. Thanks!!
Author
Owner

@eitchtee commented on GitHub (Nov 8, 2025):

For future reference: the order should not matter, but who knows. Either way, glad you got it working, hoping you like the app.

@eitchtee commented on GitHub (Nov 8, 2025): For future reference: the order should not matter, but who knows. Either way, glad you got it working, hoping you like the app.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WYGIWYH#64