I have recently host my django website on digital ocean droplet. I have set a domain name for it, and had the domain name in the setting ALLOWED_HOST variable, after push to the repo, build and deploy on digital ocean, I am getting the error Invalid HTTP_HOST header: ‘domain-name’. You may need to add ‘domain-name’ to ALLOWED_HOSTS. I check at the bottom of the debug page and find out that the value of ALLOWED_HOST doesn’t contain my domain-name, what can be the issue?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Heya,
Check
ALLOWED_HOSTS
insettings.py
Ensure your domain name is listed in
ALLOWED_HOSTS
. It should look something like this:If you’re using environment variables for production settings, make sure the domain name is correctly passed to the
ALLOWED_HOSTS
variable.For example, in
settings.py
:Check the code on your Droplet and make sure that settings.py is actually being updated. Also, what do you mean by build and deploy? Can you give more info about your workflow?
Hi there!
There are a few things that you could check here starting with the
ALLOWED_HOSTS
setting insettings.py
and making sure that it is correctly set with your domain name:If you’re deploying with environment variables, make sure they are properly set and imported:
Check if the environment variable
DJANGO_ALLOWED_HOSTS
is set in your droplet.After that, if you use caching (e.g., with
gunicorn
oruwsgi
), restart your Django server to apply the new settings:Or if you are using a Docker container, rebuild and restart it:
On another note, if
DEBUG
is set toTrue
in production, it could cause unexpected behavior. Make sure to set it toFalse
:If this is still not working, I would suggest checking your logs for more details:
Let me know how it goes!
- Bobby