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, @b9f220d82ec74dcdbabcaff6fa4fde
If you are using a caching mechanism (Redis, Memcached), clear it to ensure stale configurations are not affecting your application.
Also you can ensure the deployed version of your
settings.py
or its equivalent configuration file on the DigitalOcean droplet matches your local changes. Sometimes, deployment scripts might not push updates correctly.Regards
Heya,
If your Allowed_host has not been updated it means that your Application has not picked up the new settings. For that to work, sometimes you nead to restart your application.
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