Multiple wildcard server_name

Daniel L. Miller dmiller at amfes.com
Mon Sep 5 19:25:41 UTC 2022


While I'm sure this is documented somewhere - I haven't found exactly 
what I'm looking for. Or I'm just not understanding what I've read.

My understanding is simply prefixing a server name with ".", such as 
".example.com", is a special wildcard that basically becomes 
"example.com *.example.com". My current nginx version is 1.20.2.

I have a number of domains that I want to re-direct to a master name. 
And I want http re-directed to https. So I have:

server {
     listen 80 default_server;
     server_name
         .maindomain.com
         .example1.com
         .example2.com
         .example3.com

     location / {
         return 301 https://maindomain.com$request_uri; 
<https://amfes.com$request_uri;>
     }
}

server {
     listen 443 ssl http2 default_server;
     server_name_in_redirect on;

     server_name maindomain.com www.maindomain.com *.maindomain.com;
}

Based on the docs, I recently changed by second server block from just 
".maindomain.com" to the explicit matching for faster default 
processing.

This works for "https://maindomain.com" and "http://maindomain.com". 
Also for both protocols for "www.maindomain.com". And - it works for 
"www.example1.com" as well as the other alternate domains with a "www" 
prefix. But it does not work for just "example1.com" or the other 
domains. It doesn't appear to be DNS - both the base domain and the 
"www" A records point to the same IP. What I'm receiving is a 404 Not 
Found for either "http://example1.com" (which does not re-direct to 
https) or "https://example1.com". And I don't understand why.

--
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20220905/e962e636/attachment.htm>


More information about the nginx mailing list