I'm trying to run two domains, one with a wildcard certificate and the other one with a regular certificate from one IP and one nginx.
Setup: example1.com with wildcard certificate example2.com with regular certificate
My current nginx config for my wildcard setup looks like this (I haven't started with adding the second domain yet):
/etc/nginx/sites-available/example1.com:
server {
listen 443 default_server ssl;
server_name _;
ssl_certificate /etc/nginx/ssl/example1.com/example1.com.crt;
ssl_certificate_key /etc/nginx/ssl/example1.com/example1.com.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# Perfect Forward Security
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS +RC4 RC4";
}
server {
listen 443;
server_name example1.com;
error_log /var/log/nginx/example1.com.error.ssl.log;
access_log /var/log/nginx/example1.com.access.ssl.log;
root /var/www/example1.com/;
index index.html;
}
server {
listen 80;
server_name example1.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
Now I also have some subdomains, that's why I'm using a wildcard certificate. The subdomain configs just looks like this:
/etc/nginx/sites-available/sub1.example1.com
server {
listen 443;
server_name sub1.example1.com;
error_log /var/log/nginx/sub1.example1.com.error.ssl.log;
access_log /var/log/nginx/sub1.example1.com.access.ssl.log;
root /var/www/sub1.example1.com/;
location / {
# nothing
}
}
server {
listen 80;
server_name sub1.example1.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
This setup is pretty neat because all the subdomains are inheriting the ssl settings from the example.com
config because it's the default_server
.
What's the best way of adding a second domain now? If I just add the domain the same way I'll obviously get an error on launch because there's a duplicate default_server
entry. If I remove the default_server
entry from example2.com
's config it'll fall back to the ssl config from example1.com
.
What I want but don't know how to achieve:
Have one "main" config for each domain, let's call it example1.com-default
and example2.com-default
.
These configs should include all the settings that are common between the different subdomains, like the SSL config, Perfect Forward Security,... and the different subdomains would just be smaller configs who inherit these settings from their respective main domain.
So sub1.example1.com
would inherit the SSL settings from example1.com-default
and sub1.example2.com
would inherit the SSL settings from example2.com-default
.
Is this possible, and if it is how would I achieve this?
Thanks in advance!