nginx 的location 的用法


相信信息如下:http://nginx.org/en/docs/http/ngx_http_core_module.html#location


location 的语法匹配的格式:

location [=|~|~*|^~]  patt {

}


location = patt {} [精准匹配]

location patt{}  [一般匹配]

location ~ patt{} [正则匹配]





1、 匹配的规则为:

        先去匹配精准匹配,如果精辟匹配不成功则会去匹配一般匹配,再次为正则匹配。

        匹配实例为:

         

       1) 精准匹配

        location = /  {
            root   html;
            index  a.html  index.html index.htm;
        }


       2)   一般匹配

          location  =/   {
            root   html;
            index  a.html  index.html index.htm;
        }


        3)、  正则匹配

        location ~ image {

           root /var/www/;

           index index.html;

         }

        

      4) 正则匹配

       location / image {

           root /var/www/;

           index index.html;

         }




     注意 : 1)、 ~ image 正则匹配时会把image目录带上,在root把最后的image的目录去掉。 

                正则匹配时匹配上第一个就会返回。

               2) 在一般匹配时匹配记忆最长的结果

               

     













评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

盒马coding

你的支持是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值