Question

Let's encrypt for multiple sites with different domains on same droplet

I’m running Debian 9.2 with nginx and let’s encrypt on a single droplet. I have got SSL to work on fine after following the tutorial for one domain with this default setup in sites-available:

server {
        listen 80;
        server_name primarydomain.com www.primarydomain.com;
        return 301 https://$server_name$request_uri;
}
server {
        # SSL configuration
        listen 443 ssl;

        server_name .primarydomain.com;

        root /usr/share/nginx/html/primarydomain.com;

        include /etc/nginx/sites-available/include;

        include snippets/ssl-primarydomain.com.conf;
        include snippets/ssl-params.conf;
}

But then I wanted to have another domain as well as subdomain connected to the same droplet but another /usr/share/nginx/html/ folder so I set it up like this:

#Primary
server {
        listen 80;
        server_name primarydomain.com www.primarydomain.com;
        return 301 https://$server_name$request_uri;
}
server {
        # SSL configuration
        listen 443 ssl;

        server_name .primarydomain.com www.primarydomain.com;

        root /usr/share/nginx/html/primarydomain.com;

        include /etc/nginx/sites-available/include;

        include snippets/ssl-primarydomain.com.conf;
        include snippets/ssl-params.conf;
}

#Test.Primary
server {
        listen 80;
        server_name test.primarydomain.com www.test.primarydomain.com;
        return 301 https://$server_name$request_uri;
}
server {
        # SSL configuration
        listen 443 ssl;

        server_name test.primarydomain.com www.test.primarydomain.com;

        root /usr/share/nginx/html/test.primarydomain.com;

        include /etc/nginx/sites-available/include;

        include snippets/ssl-primarydomain.com.conf;
        include snippets/ssl-params.conf;
}

#Secondary
server {
        listen 80;
        server_name secondarydomain.com www.secondarydomain.com;
        return 301 https://$server_name$request_uri;
}
server {
        # SSL configuration
        listen 443 ssl;

        server_name .secondarydomain.com www.secondarydomain.com;

        root /usr/share/nginx/html/secondarydomain.com;

        include /etc/nginx/sites-available/include;

        include snippets/ssl-primarydomain.com.conf;
        include snippets/ssl-params.conf;
}

Unfortunately this did not work out at all as I thought it would. Is it something with let’s encrypt I need to configure that I’ve missed perhaps?


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 followed the same tutorials but I get a weird error. I have two root domains on the same server/droplet. Both have separate server block files with different root paths. One has SSl while the other does not. One website (with ssl) is working fine. The second website (without ssl) keeps redirecting to the first one. Any thoughts?

Hello,

What I would suggest is creating separate files for your server blocks and then using CertBot.

Here’s a step by step guide on how to install CertBot and secure your Nginx server with it:

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-debian-9

I’ve been using it for a while now and I can say that it is just a spot on and it works every time.

Regards, Bobby