当前位置:网站首页>III. servername matching rules

III. servername matching rules

2022-06-09 15:23:00 Little silly bird_ coding

servername A variety of matching methods

ServerName Matching rules

We can have the same servername Configure multiple domain names under the file

1. Complete match

You can directly configure two domain names here , Just visit either of these websites , Back to this video Under the table of contents

   server {
    
        listen       80;
        server_name xiaodainiao.com   xiaodainiao1.com

        location / {
    
            root   /www/video;
            index  index.html index.htm;
        }

2. Wildcard match

* The number can be any value , except www, There are others ahead , The directories accessed are all video

Be careful : Writing that first will match which one first , If they match, they won't look down .

  server {
    
        listen       80;
        server_name  www.xiaodainiao.com    
   
   location / {
    
        root   /www/www;
        index  index.html index.htm;
    }

server {
    
        listen       80;
        server_name  *.xiaodainiao.com    
   
   location / {
    
        root   /www/video;
        index  index.html index.htm;
    }

3. Wildcard end match

  server {
    
        listen       80;
        server_name  www.xiaodainiao.com    // Only visit www.xiaodainiao.com To match this 
   
   location / {
    
        root   /www/www;
        index  index.html index.htm;
    }

server {
    
        listen       80;
        server_name  www.xiaodainiao.*        // visit www.xiaodainiao.org It will match this after a while  
   
   location / {
    
        root   /www/video;
        index  index.html index.htm;
    }

4. Regular matching

server {
    
        listen       80;
        server_name  ~^[0-9]+\.xiaodainiao\.com$;
   
   location / {
    
        root   /www/video;
        index  index.html index.htm;
    }

visit :666.xiaodainiao.com It will jump to video below

原网站

版权声明
本文为[Little silly bird_ coding]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091458061649.html