Nginx uses regular expressions to automatically match wildcard domain names to directories Nginx can be used to realize the function of virtual host and bind multiple URLs. Basic writing The most basic way to write it is server{ listen 80; server_name www.a.com; root /html/a; … } server{ listen 80; server_name www.b.com; root /html/b; … } Regular expression After the domain name is bound, it is automatically matched to the corresponding directory, and there is no need to write configurations for each domain name one by one. server { listen 80; # $subdomain will match the second-level domain name and above # $domain will match the first-level domain name # $tld will match the root node name server_name ~^((?<subdomain>.*)\.)?(?<domain>[^.]+)\.(?<tld>[a-zA-Z]+)$; #If there is no $subdomain, jump to www if ($subdomain = "") { # set $subdomain "_"; set $subdomain "www"; return 301 $scheme://www.$domain.$tld$request_uri; } root /usr/share/nginx/html/${domain}.${tld}/${subdomain}; } other There are many articles about nginx's matching order, so I won't go into details. Most people don’t have so many domain names to match. Instead, they want to block some malicious domain name pointers. However, when testing, in order not to affect the running web page, you can add an IP domain name record in the hosts and use a non-existent domain name for testing, which is more useful at this time. Summarize This is the end of this article about how nginx uses regular expressions to automatically match wildcard domain names to directories. For more information about how nginx uses regular expressions to match wildcard domain names to directories, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL optimization tips: analysis of duplicate removal implementation methods [millions of data]
>>: JS implements city list effect based on VUE component
Flex layout is a commonly used layout method nowa...
Preface Due to the weak typing of JS, loose writi...
The action of the form is different from the URL j...
Table of contents 1. Install vmware 1.1 Download ...
Table of contents Create a new user Authorize new...
The TextBox with the ReadOnly attribute will be di...
Table of contents 1. Ref and reactive 1. reactive...
I am using the Ubuntu 16.04 system here. Installa...
When it comes to remote desktop connection to Lin...
Docker includes three basic concepts: Image: A Do...
Background requirements: As the business grows la...
Software version and platform: MySQL-5.7.17-winx6...
Preface: Vue3.0 implements echarts three-dimensio...
This article shares the specific code of JavaScri...
Table of contents Scene Introduction Plugin Imple...