您的位置:首页 > 运维架构 > Nginx

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

2015-03-21 14:52 393 查看
验证代码:    

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中处理。)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx重写 rewrite