For the bulk add http://www.aliyun.com/zixun/aggregation/14840.html "> Virtual host needs, Apache has Vhost_alias module to help. What about Nginx? In fact, the horse does not need, the same can be achieved Nginx two-level domain name matching subfolders, and does not match the "www", but can match the inclusion of "www" subdomain.
First look at the current online search methods.
if ($host ~* (. *) \. *)\. (.*)) {Set $subdomain $} Location/{root HTML $subdomain; index index.html index.php;}
The above "~*" means case-insensitive, and then matches any "xxx.xxx.xxx" type of URL, and finally a tragedy, not only to match the "www.yourdomian.com" or even "I 艹. $!@.com" Such URLs also match.
Yes, that's right! This is a regular question. It is recommended that you read the regular expression 30-minute introductory tutorial, the Nginx Location instruction basics, and then look down ...
Perfect solution
if ($host ~* B (?! www\b) W) \.\w+\.\w+) {set $subdomain/$1;} Location/{Root/home/wangyan/public_html$subdomain index index.html index.php;}
effect, the following figure can be seen, has been implemented, does not match the "www" but can match the inclusion of "www" subdomain.
Use the method, copy the code above to the server {} tab, and then restart Nginx.
Original address: https://wangyan.org/blog/nginx-subdomain.html
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.