I have a Django application on an Ubuntu 22.04 droplet with Gunicorn and Nginx. I added DNS for my domain (ifbt.farm), which is resolving to my ip address (24.199.74.74). If I configure nginx with
server_name 24.199.74.74;
and sudo systemctl restart nginx
It proxies the request to Gunicorn correctly so I see my application when I visit https://24.199.74.74
but if I configure it with
server_name ifbt.farm www.ifbt.farm;
and sudo systemctl restart nginx
It gives the ‘Welcome to nginx’ error page when I visit https://ifbt.farm. My Django settings has
ALLOWED_HOSTS = [‘ifbt.farm’, ‘www.ifbt.farm’, ‘24.199.74.74’]
This link on stack overflow notes a similar problem, and the OP solved it by commenting out the server_name line in sites-available/default, which he said was shadowing it. I tried that, but it didn’t change anything in my case.
Thanks for any thoughts on this!
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.
This must have been a DNS resolution issue. About two hours after I posted this question (two days ago), it started working correctly without me making any further changes!
Thanks, Bobby for following up!
Hi there,
It looks like that you’ve managed to get it all working! Happy to see that. If you have a chance feel free to share your solution here with the community.
In general, this issue could be due to a number of reasons. Here are some debugging steps:
/etc/nginx/sites-available/
directory. Here is an example of what your configuration should look like:Please replace
/path/to/your/gunicorn.sock
with the path to your Gunicorn socket file.Check Your DNS Settings: Double-check your DNS settings and make sure that your domain name is properly pointing to your droplet’s IP address. There could be a delay between setting the DNS record and it taking effect due to DNS propagation.
Check Server Block Symbolic Link: When you create a server block file in the
/etc/nginx/sites-available/
directory, you must create a symbolic link to it in the/etc/nginx/sites-enabled/
directory for Nginx to serve it. To create a symbolic link, you can use theln
command:Replace
yourconfig
with the name of your Nginx configuration file./var/log/nginx/error.log
. You can tail the file by typing:This command will display the last few entries in the file and then display new entries as they are added.
Here is also a nice tutorial on how to troubleshoot common Nginx problems:
Best,
Bobby