When configuring nginx, server_name needs to configure multiple second-level domain names. Refer to this article, the original text http://bneijt.nl/blog/post/name-based-vi...
Excerpts are as follows:
server {
server_name ~^((?<subdomain>.*)\.)?(?<domain>[^.]+)\.(?<tld>[^.]+)$;
if ($subdomain = "") {
set $subdomain "_";
}
location / {
index index.html;
root /srv/http/vhost/${domain}.${tld}/${subdomain};
}
}
My configuration is slightly modified based on this, the content is as follows:
server {
server_name ~^((?<subdomain>.*)\.)aa\.com$;
if ($subdomain = "") {
set $subdomain "www";
}
location / {
root /var/www/${subdomain}.aa.com/public;
index index.html index.htm;
}
}
Problem:
When the subdomain is empty, it cannot be converted to www. That is, if you enter www.aa.com in the browser, you can access it, but if you enter aa.com directly, It cannot be accessed. Is it a problem with the regular expression ~^((?<subdomain>.*)\.)aa\.com$
or another problem?
Change the regular expression to:
~^((?<subdomain>.*).)?aa.com$
Try it
Note, it is not verified in the environment.
There is also domain name access, which requires domain name resolution and configuration of A records.
www.aa.com and aa.com require two A records.
Best, check both places.