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?
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!
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
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.