I want to serve an website via https://the.example.com
(thus with a non-standard sub-domain), but the same website should also be entered with https://example.com
and https://www.example.com
(+the http
counterparts).
So if you type https://www.example.com/page
you should be redirected to https://the.example.com/page
, and if you type http://example.com/page
you should be redirected to the same page.
I made this now with nginx for http
like this:
server {
listen 80;
server_name example.com www.example.com the.example.com;
return 301 https://the.example.com$request_uri;
}
and this block for the non-standard https
URL's:
server {
listen 443 ssl http2;
server_name www.example.com example.com;
location /.well-known/ {
allow all;
}
location / {
return 301 https://the.example.com$request_uri;
}
}
and this block for the actual (canonical) website:
server {
listen 443 ssl http2;
server_name the.example.com;
location ...
}
I left out most lines for brevity. I only want one redirect, before you are on the real site.
The http
-site and the canonical https
-site work, but I get certificate problems with https://www.example.com
and https://example.com
.
I requested three certificates, like so:
certbot certonly --webroot -w "/some/root" -d www.example.com -m user@examp.e.com --agree-tos
certbot certonly --webroot -w "/some/root" -d example.com -m user@examp.e.com --agree-tos
certbot certonly --webroot -w "/some/root" -d the.example.com -m user@examp.e.com --agree-tos
How is this supposed to work? Should the sub-sites have their own webroot
, or should the webroot and/or certificate be shared? I'm a bit lost here as to what is happening...