Set up Django, Nginx and Ubuntu 18.04 - "welcome to nginx" landing page displays when www. prefix is loaded with domain. Works fine without.


Warning - Complete newbie here.

I’ve followed the below guide “How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 18.04” to set up my Django website.

Everything works fine when i search for my website via “”, however when i search for “” i get a welcome to nginx landing page.

I’ve attempted to fix this by adding the “www.” prefix version of my domain to the server_name line in my server block as per below.

server {
    listen 80;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/peter/websitedirectory;

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;

However when running sudo nginx - t on the above, i get a warning:

nginx: [warn] conflicting server name: “” on, ignored

I’m not entirely sure what this means. I feel like this should be relatively simple to fix, can anyone help? Thanks!

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I had the same issue.

  1. To solve it open your nginx file:
sudo nano /etc/nginx/sites-available/YOURPROJECTNAME

  1. Change this line (Change domains below to yours but preserve prefix):

  1. Check if file is error-free:
sudo nginx -t

  1. Restart nginx:
sudo systemctl reload nginx

I took the code from Digital Ocean tutorial, thanks to them for these great articles!


I am not sure if you still need this but what worked for was to add below to /etc/nginx/sites-available/yourprojectname:

server { if ($host = { return 301 https://$host$request_uri; } # managed by Certbot

listen 80;
return 404; # managed by Certbot


I didn’t disable default file just added that- of course adjust to your domain.

Your default file has server_name _; which will match any host (including what you’re seeing with Just disable the “default” file completely. Also change this line:

 if ($host = {


 if ($host ~ "") {

And change this line:




Then restart Nginx.