By Dow Drake
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!
Accepted Answer
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:server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location / {
include proxy_params;
proxy_pass http://unix:/path/to/your/gunicorn.sock;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
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 the ln
command:
sudo ln -s /etc/nginx/sites-available/yourconfig /etc/nginx/sites-enabled/
Replace yourconfig
with the name of your Nginx configuration file.
/var/log/nginx/error.log
. You can tail the file by typing:sudo tail -f /var/log/nginx/error.log
This command will display the last few entries in the file and then display new entries as they are added.
sudo systemctl restart nginx
Here is also a nice tutorial on how to troubleshoot common Nginx problems:
https://www.digitalocean.com/community/tutorials/how-to-troubleshoot-common-nginx-errors
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.