Nginx uses a unified certificate for multiple secondary domain names?

premise

  1. I have a certificate containing the pan-domain name ( * .example.com and example.com );
  2. my purpose nginx, all example.com primary and secondary domain names use this certificate;

implementation

method 1: verification passed, but too much redundant code

each matching domain name loads a certificate, which is too cumbersome, because the certificate is all the same

.
-sharp   server_name 
server {
    listen 443;
    server_name *.example.com example.com;
    ssl on;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
}

-sharp example.com
server {
    listen 443;
    server_name example.com;
    location / {
        ...
    }
}
-sharp aaa.example.com
server {
    listen 443;
    server_name aaa.example.com;
    location / {
        ...
    }
}
-sharp bbb.example.com
server {
    listen 443;
    server_name bbb.example.com;
    location / {
        ...
    }
}

question

how to load certificates without encumbrance (all certificates follow a unified path)?

Apr.28,2022

nginx supports include

-sharp ssl_certificate.conf 
ssl on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

-sharp   server_name 
server {
    listen 443;
    server_name *.example.com example.com;
    
    include ssl_certificate.conf;
}

-sharp example.com
server {
    listen 443;
    server_name example.com;

    include ssl_certificate.conf;

    location / {
        ...
    }
}

I see, thank you
to ask you another question, does nginx have anything like a master switch?
that's it

 {
    -sharp  server () 
}
server {
    -sharp server 1 ...
}
server {
    -sharp server 2 ...
}
...
 {
    -sharp  server () 
}

I don't know if there is any?

Menu