I’m a little perplexed at the moment and not seeing where I messed up. I have seven domains on a single droplet. When I migrated to DigitalOcean last week I brought with me five of them. I setup the Ubuntu 18.04 droplet, Nginx, and Certbot without issue for them. I followed along with How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS and How To Secure Nginx with Let’s Encrypt on Ubuntu 18.04 for the last two without any issues.

Then a few days ago I acquired two more domains and did the exact same things as before but that last domain I added is getting a 404 page.

The configuration file looked right, was in sites-available with symlink in sites-enabled. Thinking I might of screwed up I deleted everything related to that domain and did it again. Still got the default nginx 404 page for it. I looked around the other questions but didn’t see anything that was helpful, or perhaps it was but was above me currently. I went ahead and removed everything related to that domain one more time and did all the nginx steps one more time.

Bellow is the config file without the comments. Domain name has been changed to sample07.com.

server {
    listen 80;
    listen [::]:80;

    root /var/www/sample07.com/html;

        index index.html index.htm index.nginx-debian.html;

    server_name sample07.com www.sample07.com;

    location / {
        try_files $uri $uri/ =404;
    }
}

In nginx.conf I have..

    server_names_hash_bucket_size 64;

Now something odd I noticed looking at my first domain config file was Certbot seems to have added in the information for my last domain. I’ve renamed my first domain as sample01.com and removed the standard comments, however I have added my own comment.

server {

    root /var/www/sample01.com/html;

    index index.html index.htm index.nginx-debian.html;

    server_name sample01.com www.sample01.com;

    location / {
        try_files $uri $uri/ =404;
    }

    listen [::]:443 ssl; 
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/sample01.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/sample01.com/privkey.pem; 
    include /etc/letsencrypt/options-ssl-nginx.conf; 
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 

}

server {
    if ($host = www.sample01.com) {
        return 301 https://$host$request_uri;
    } # 


    if ($host = sample01.com) {
        return 301 https://$host$request_uri;
    } # 

    listen 80 default_server;
    listen [::]:80 default_server;

    server_name sample01.com www.sample01.com;
    return 404; 
}

# Now it looks like it added this..
server {
    if ($host = www.sample01.com) {
        return 301 https://$host$request_uri;
    } # 

    if ($host = sample01.com) {
        return 301 https://$host$request_uri;
    } 


    server_name www.sample07.com sample07.com; 
    return 404; 


    listen [::]:443 ssl; 
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/sample07.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/csample07.com/privkey.pem; 
    include /etc/letsencrypt/options-ssl-nginx.conf; 
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

Wondering if it was something wrong with how I used Certbot I cleared out the references for the seventh domain in the first domains config. I then removed the SSL certificates for the seventh domain and ran it all again. The results were that I got references again in the first domain config for the seventh. It was around this time that I looked at Nginx error.log file and I saw this..

2020/04/02 19:19:32 [warn] 13752#13752: conflicting server name "sample07.com" on [::]:80, ignored
2020/04/02 19:19:32 [warn] 13752#13752: conflicting server name "sample01.com" on [::]:80, ignored

Moving on, I opened up the configs of the first domain (sample01.com), a known good domain (sample02.com), and the one giving me the issues (sample07.com). I noticed for sample07.com that I got the if($host.. statements but none of the block pointing to the certificate. Comparing to sample02.com I changed the config for sample07.com to be this…

server {

    root /var/www/sample07.com/html;

    index index.html index.htm index.nginx-debian.html;

    server_name sample07.com www.sample07.com;

    location / {
        try_files $uri $uri/ =404;
    }

  listen [::]:443 ssl;
  listen 443 ssl;
  ssl_certificate /etc/letsencrypt/live/sample07.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/sample07.com/privkey.pem; 
  include /etc/letsencrypt/options-ssl-nginx.conf; 
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

}

server {
    if ($host = www.sample07.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = sample07.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;

    server_name www.sample07.com sample07.com; 
    return 404; 
}

In addition I removed the references in the first domains config to the seventh ones. However, still the 404 page for the seventh domain. So yeah, I give up. lol. Taking one last look at error.log I see this now..

2020/04/02 20:41:42 [warn] 14227#14227: conflicting server name "sample01.com" on 0.0.0.0:80, ignored
2020/04/02 20:41:42 [warn] 14227#14227: conflicting server name "sample01.com" on [::]:80, ignored

So maybe that’s an improvement?

Please let me know if y'all need more info and the like. I look forward to see what'cha all think. Thank you.

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.

×
1 answer

Hi there @MrLetter,

Indeed it looks like that you now have a duplicate entry for the 443 server block for your sample01.com website.

I would recommend removing the duplicate entry and then giving this a try again.

A few things that I would recommend before doing this:

  • Make sure to backup your current config file

  • After making the change run a config test:

  • sudo nginx -t
  • Only if you get Syntax OK then proceed with Nginx restart:
  • sudo systemctl restart nginx

Let me know how it goes!
Regards,
Bobby

Submit an Answer