Automatically choose SSL Certificate based on accessed hostname in the same vhost
Use two server
blocks, but move the common directives into a separate file. Pull the new file into each server
block using an include
directive. See this document for more.
For example:
server {
listen 443 ssl;
server_name nextclowd.raspi.local;
# My self-signed SSL certificate
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
include /path/to/common/config;
}
server {
listen 443 ssl;
server_name mydomain.ddns.net;
# My Let's Encrypt SSL certificate
ssl_certificate /etc/letsencrypt/live/mydomain.ddns.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.ddns.net/privkey.pem;
include /path/to/common/config;
}
Do not put the common file into a directory already used by nginx
for wild-card inclusion, such as conf.d
, sites-enabled
and sites-available
.