ngnix 系列二 路径匹配

4 篇文章 0 订阅

首先看有没有精准匹配,如果有,则停止匹配过程.

location = patt {

   config A

}

如果 $uri ==patt,匹配成功,使用configA

  location = / {

              root   /var/www/html/;

            index  index.htm index.html;

       }

        

 location / {

            root   /usr/local/nginx/html;

           index  index.html index.htm;

  }

 

如果访问  http://xxx.com/

定位流程是 

1: 精准匹配中 ”/”   ,得到index页为  index.htm

2: 再次访问 /index.htm , 此次内部转跳uri已经是”/index.htm” ,

根目录为/usr/local/nginx/html

3: 最终结果,访问了/usr/local/nginx/html/index.htm

 


再来看,正则也来参与.

location / {

            root   /usr/local/nginx/html;

            index  index.html index.htm;

        }

 

location ~ image {

           root /var/www/image;

           index index.html;

}

 

如果我们访问  http://xx.com/image/logo.png

此时, “/” 与”/image/logo.png”匹配

同时,”image”正则 与”image/logo.png”也能匹配,谁发挥作用?

正则表达式的成果将会使用.

 

图片真正会访问 /var/www/image/logo.png

 

 


location / {

            root   /usr/local/nginx/html;

            index  index.html index.htm;

        }

 

location /foo {

           root /var/www/html;

            index index.html;

}

我们访问http://xxx.com/foo

 对于uri “/foo”,   两个location的patt,都能匹配他们

即 ‘/’能从左前缀匹配 ‘/foo’, ‘/foo’也能左前缀匹配’/foo’,

此时, 真正访问 /var/www/html/index.html

原因:’/foo’匹配的更长,因此使用之.;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值