码迷,mamicode.com
首页 > 其他好文 > 详细

nginx 的路径匹配

时间:2015-10-21 22:21:43      阅读:416      评论:0      收藏:0      [点我收藏+]

标签:

nginx 的路径匹配

nginx 的路径匹配

=          精确匹配, 后面是文件名, 不能是文件夹
/image     精确匹配, 后面是文件夹, 如果这个匹配到了, 还可能会被正则替换掉
^~ image   精确匹配, 后面是文件夹, 如果这个匹配到了, 不会继续匹配正则
~ image    正则
~* image   正则, 不区分大小写

匹配规则:

  1. 普通命中匹配命中最长的
    location / { ... }
    location /image { ... }
    
  2. 正则表达式一旦匹配到就不会再匹配, 因此第二条永远不会被匹配
    location ~ im {
        root   html1;
    }
    
    location ~ image {
        root   html2;
    }
    
    访问 http://xxx/image/index.html  会到 html1 文件夹里面去寻找
    
  3. 先匹配 /image, 然后再匹配 ~ image, 因此 /image 的规则会被替换掉
    location ~ image {
        root   html1;
    }
    location /image {
        root   html2;
    }
    
    访问 http://xxx/image/index.html  会到 html1 文件夹里面去寻找
    
  4. ^~ 匹配到之后就不会继续匹配正则
    location ^~ image {
        root   html1;
    }
    location /image {
        root   html2;
    }
    
    访问 http://xxx/image/index.html  会到 html1 文件夹里面去寻找
    

nginx 的路径匹配

标签:

原文地址:http://www.cnblogs.com/sunznx/p/4899087.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!