As I was following this tutorial on how to Serve multiple Django applications with Nginx and Gunicorn using multiple domains (https://www.youtube.com/watch?v=koo3bF2EPqk )
When accessing the site via my subdomain, my site is not working. I’m getting the following error
Invalid HTTP_HOST header: `'subdomain.example.com'`. You may need to add 'subdomain.example.com' to ALLOWED_HOSTS.
I have already added the same on allowed hosts and restarted nginix and Gunicorn.
I had another site which is already running with no issues. Droplet IP is being used for both domains.
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.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Heya,
there are a couple of possibilities on the origin of the error,
You have not showed what you have inside your Django
settings.py
file, but I assume you have not configured theALLOWED_HOSTS
variable as you should have. This is how it should look like:Also, make sure to restart the Nginx service after doing so. The settings file is loaded to memory, so if you make changes to it, you need to restart the server.
systemctl restart gunicorn
andsystemctl restart nginx
Hi there,
It sounds like that your Nginx configuration might be the issue if it is serving the contents of only one of the applications.
Can you share both of the Nginx server blocks that you have for each of the two websites? You need to make sure that the reverse proxy rules for each of the sites is pointing to the correct web socket.
Also, can you verify that both of the Gunicorn services are up and running?
Would you mind also sharing the
ALLOWED_HOSTS
definition for each site as well?Best,
Bobby
Thank you all, I was able to fix it by redirecting
I used this tut here https://www.digitalocean.com/community/tutorials/how-to-redirect-www-to-non-www-with-nginx-on-ubuntu-14-04#configure-nginx-redirect