实例区分nginx location中rewrite的break与last

验证代码:    

server{

       listen 80;
       server_name www.example.com;
       location ~ /test1.txt {
            rewrite /test1.txt /test2.txt break;
            #rewrite /test1.txt /test2.txt last;
       }

       location ~ /test2.txt {
           root /var/txt/;
       }

    }


文件设置: 

       验证 rewrite /test1.txt /test2.txt break; 在 /usr/local/nginx/html 有test2.txt 内容为 /usr/local/nginx/html/test2

       验证 rewrite /test1.txt /test2.txt last; /var/txt/ 有test2.txt 内容为 /var/test2

说明:

       在使用break时,www.example.com/test1.txt  rewrite 为 www.example.com/test2.txt 不向下边的location中查找,我们会查看到 /usr/local/nginx/html/test2,说明是/usr/local/nginx/html中的test2.txt

       (last其实就相当于一个新的url,对nginx进行了一次请求,需要走一遍大多数的处理过程,最重要的是会做一次find config,提供了一个可以转到其他location的配置中处理的机会,


      在使用last时,www.example.com/test1.txt  rewrite 为 www.example.com/test2.txt 并匹配下边的location。我们会查看到   /var/test2

         (break则是在一个请求处理过程中将原来的url(包括uri和args)改写之后,在继续进行后面的处理,这个重写之后的请求始终都是在同一个location中处理。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值