Solution to Django Invalid HTTP HOST header Error
If you are getting an error when publishing your Django project using a domain name, the reason is that the proxy HOST information in the HTTP service is incorrect. In other words, if there is a service such as unicorn, NGINx or Apache sends the HOST information incorrectly when redirecting to the unicorn via proxy.
proxy_set_header Host '$http_host';
If additional characters are added to the '$http_host' section, this URL like \\ is sent to uvicorn and the URL rules cannot be matched.
NGINX sample code:
location / {
proxy_set_header Host '$http_host';
proxy_set_header X-Forwarded-For '$proxy_add_x_forwarded_for';
proxy_set_header X-Forwarded-Proto '$http_x_forwarded_proto';
proxy_redirect off;
proxy_pass http://notifytube_django3;
proxy_connect_timeout 500;
proxy_read_timeout 600;
}
NOTE: Finally, do not forget to restart the NGINX service.
Can't find the information you're looking for?
You have examined the knowledge base in detail, but if you cannot find the information you need,
Create a Support Ticket-
How to Open Ports in Windows?
313 2
-
How to Grant Windows Administrator Privileges?
229 0
-
How to install Webmin on Ubuntu?
882 2
-
Linux SSH Terminal Commands and Explanations
797 3
-
CentOS Stream 10 Update Commands
856 1
-
CentOS Stream 9 Update Commands
1248 2
-
CentOS Stream 8 Update Commands
675 0
-
What is FreeBSD?
857 2
-
Out: 452 4.3.1 Insufficient system storage
768 2
-
Turning Off Automatic Updates in Windows Operating Systems
879 0