Nginx location 匹配规则

匹配规则
= > ^~ > 顺序依次匹配正则表达式 location(如果没有, 就匹配最长的) >最长匹配的 location

/Test1 匹配第六条
/Test1/ 比第一个长, 所以匹配第三条
/Test1/Test2 匹配第二条
/Test1/Test2/ 第四条
/test1/Test2 第二条





server {
        server_name location.liuhonghe.me;
        error_log  logs/error.log  debug;
        #root html/;
        default_type text/plain;
        merge_slashes off;
        location ~ /Test1/$ { # 第一条
                return 200 'first regular expressions match!\n';
          }

          location ~* /Test1/(\w+)$ { # 第二条
                  return 200 'longest regular expressions match!\n';
          }

          location ^~ /Test1/ { # 第三条
                  return 200 'stop regular expressions match!\n';
          }

          location /Test1/Test2 { # 第四条
                  return 200 'longest prefix string match!\n';
          }

          location /Test1 { # 第五条
                  return 200 'prefix string match!\n';
          }


          location = /Test1 { # 第六条
                  return 200 'exact match!\n';
          }

  }
posted @ 2019-05-25 16:49  reaperhero  阅读(192)  评论(0编辑  收藏  举报