一、环境准备

资源文件创建

mkdir -p /opt/tmp/wqy/test/aaa
mkdir -p /opt/tmp/wqy/test/bbb
echo "aaa" >> /opt/tmp/wqy/test/aaa/index.html
echo "bbb" >> /opt/tmp/wqy/test/bbb/index.html

二、测试过程

2.1、初始配置时

nginx配置

server {
listen 80;
server_name wqy.test.com;
access_log logs/wqy-test-com/access.log;
location ^~ /aaa {
root /opt/tmp/wqy/test;
}
location ^~ /bbb {
return 200 "hello world\n";
}
}

测试结果

#curl -s http://wqy.test.com/aaa/index.html -x 127.0.0.1:80
aaa
#curl -s http://wqy.test.com/bbb/index.html -x 127.0.0.1:80
hello world

2.2、配置rewrite last时

nginx配置

server {
listen 80;
server_name wqy.test.com;
access_log logs/wqy-test-com/access.log;
location ^~ /aaa {
rewrite ^/aaa/(.*) /bbb/$1 last;
root /opt/tmp/wqy/test;
}
location ^~ /bbb {
return 200 "hello world\n";
}
}

测试结果

#curl -s http://wqy.test.com/aaa/index.html -x 127.0.0.1:80
hello world
#curl -s http://wqy.test.com/bbb/index.html -x 127.0.0.1:80
hello world

url由重写前的http://wqy.test.com/aaa/index.html变为http://wqy.test.com/bbb/index.html,重新进行location匹配后,匹配到第二个location条件,所以请求url得到的响应是hello wold

测试结论

配置rewrite last时,请求跳出当前location,进入server块,重新进行location匹配,超过10次匹配不到报500错误。客户端的url不变

2.3、配置rewrite break时

nginx配置

server {
listen 80;
server_name wqy.test.com;
access_log logs/wqy-test-com/access.log;
location ^~ /aaa {
rewrite ^/aaa/(.*) /bbb/$1 break;
root /opt/tmp/wqy/test;
}
location ^~ /bbb {
return 200 "hello world\n";
}
}

测试结果

#curl -s http://wqy.test.com/aaa/index.html -x 127.0.0.1:80
bbb
#curl -s http://wqy.test.com/bbb/index.html -x 127.0.0.1:80
hello world

url由重写前的http://wqy.test.com/aaa/index.html变为http://wqy.test.com/bbb/index.html,nginx按照重写后的url进行资源匹配,匹配到的资源文件是/opt/tmp/wqy/test/bbb/index.html,所以请求url得到的响应就是/opt/tmp/wqy/test/bbb/index.html文件中的内容:bbb

测试结论

配置rewrite break时,请求不会跳出当前location,但资源匹配会按照重写后的url进行,如果location里面配置的是proxy_pass到后端,后端服务器收到的请求url也会是重写后的url。客户端的url不变。

nginx中break和last的区别的更多相关文章

  1. nginx中root和alias的区别

    nginx中root和alias的区别    

  2. python中break和continue的区别

    python中break和continue的区别   break和continue 1.break 意思为结束循环   例: i = 0 while i<10:     i+=1     if ...

  3. 关于python中break与continue的区别

    在python中break和continue都有跳出循环体的作用,但是他们还是有一些区别的,具体区别如下: break:是直接跳出循环,跳出自己所处的整个循环体 continue:只是跳出本次循环,而 ...

  4. 循环内的switch中break和continue使用区别

    首先看下break和continue的使用方法. break语句在循环和switch语句中使用,用于终止最近的封闭代码块,如果在嵌套循环中,则只终止最近的循环. continue语句在循环中使用,不能 ...

  5. javascript中break和continue的区别

    1.break:跳出循环. 2.continue:跳过循环中的一个迭代.(迭代:重复反馈过程的滑动,其目的是为了逼近所需目标或结果.每一次对过程的重复称为一次"迭代",而每一次迭代 ...

  6. Java中 break continue return 的区别

    1.break break :跳出当前循环:但是如果是嵌套循环,则只能跳出当前的这一层循环,只有逐层break才能跳出所有循环: ; i < ; i++) { ) { break; // 在执行 ...

  7. python中break continue exit() pass区别

    1.break break是终止本次循环,比如你很多个while循环,你在其中一个while循环里写了一个break,满足条件,只会终止这个while里面的循环,程序会跳到上一层while循环继续往下 ...

  8. Java中break和continue的区别

    continue,继续下一个循环的运算, break,跳出循环

  9. js中(break,continue,return)的区别

    break 一般用于跳出整个循环(for,while) continue  跳出本次循环,进入下一次循环 return 只能出现在函数体内,一旦执行return,后面的代码将不会执行,经常用retur ...

随机推荐

  1. 170830-关于JdbcTemplate的练习题以及其中的问题

    实验1:测试数据源 在spring文件中配置: 测试数据源: 结果: 实验2:将emp_id=5的记录的salary字段更新为1300.00[更新操作] update函数中,第一个是sql语句,后面的 ...

  2. [转]Linux下防止进程使用swap及防止OOM机制导致进程被kill掉

    首先解释两个概念:swap:在linux里面,当物理内存不够用了,而又有新的程序请求分配内存,那么linux就会选择将其他程序暂时不用的数据交换到物理磁盘上(swap out),等程序要用的时候再读进 ...

  3. Taylor Swift -《Fearless》

    最近网上都搜不到Taylor的歌了,分享一张love best的album给大家,支持霉霉的还是去买正版把~ 专辑曲目: 01. “Jump Then Fall” 03:5702. “Untoucha ...

  4. navigator组件(相当于a标签)

    navigator组件:页面链接: navigator组件属性: target:类型 字符串 在哪个目标上发生跳转,默认当前小程序 属性值:self 当前小程序 miniProgram 其他小程序 u ...

  5. leetcode-mid-array-3 Longest Substring Without Repeating Characters

    mycode  99.21% class Solution(object): def lengthOfLongestSubstring(self, s): """ :ty ...

  6. springboot定时任务出错 Unexpected use of scheduler.

    java.lang.IllegalStateException: Unexpected use of scheduler. 在启动类加: @Bean public ThreadPoolTaskSche ...

  7. 使用Dockerfile封装Django镜像

    第一步: 在/opt下建立了docker目录,下载一个django-2.1.7的源码包, touch Dockerfile和run.sh,其中run.sh是用来执行Django的bash脚本,Dock ...

  8. loc() iloc() at() iat()函数

    1 四个函数都是用于dataframe的定位 []用于直接定位. loc()函数是用真实索引,iloc()函数是用索引序号. loc()函数切片是左闭右闭,iloc()函数切片是左闭右开. at(), ...

  9. 【ABAP系列】SAP F4搜索帮助的高级版

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP F4搜索帮助的高级版   ...

  10. 【报错】springboot thymeleaf超链接跳转 404

    Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as ...