一、环境准备

资源文件创建

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. python 获取某个文件下的所有文件

    import os files = os.listdir(load_Graph_file_path) cnt = 0 for file in files: print(file) if (os.pat ...

  2. ES的副本数量、插入大批量数据前,副本数应该设置为0

    多副本可以提升检索的能力,但是如果副本数量太多,插入数据的时候容易出现卡顿现象: 因为主分片要把数据同步给所有的副本,所以建议副本数量最好是1-2个: ---- Es在索引数据的时候,如果存在副本,那 ...

  3. iOS-7-Cookbook

    https://github.com/liubin1777/iOS-7-Cookbook 版权声明:本文为博主原创文章,未经博主允许不得转载.

  4. CMakeLists.txt 语法

    命令不区分大小写(参数区分大小写) add_executable(demo main.cpp main.h main.rc) 用main.cpp源文件,main.h文件,main.rc文件构造可执行文 ...

  5. MongoDB学习【四】—pymongo操作mongodb数据库

    一.pymongodb的安装 Python 要连接 MongoDB 需要 MongoDB 驱动,这里我们使用 PyMongo 驱动来连接. pip安装 pip 是一个通用的 Python 包管理工具, ...

  6. Delphi XE2 之 FireMonkey 入门(23) - 数据绑定: TBindingsList: TBindExpression

    准备用 TBindingsList 重做上一个例子. 可以先把 TBindingsList 理解为是一组绑定表达式(TBindExpression)的集合;官方应该是提倡在设计时完成 TBindExp ...

  7. 类Thread

    public final void join() throws InterruptedException /* * public final void join() * throws Interrup ...

  8. 利用python+tkinter做一个简单的智能电视遥控器

    要通过python实现遥控器功能分两步: 第一步:开发图形化界面,以暴风TV的遥控器按钮为例 第二步:使PC端给电视发送相应指令(此步骤需要打开电视的adb开关) 现在就开始第一步操作实现遥控器功能, ...

  9. Jmeter JDBC请求-----数据库读取数据进行参数化 通过SSH跳板机连接数据库

    前期准备: jdbc驱动:mysql-connector-java-5.1.7-bin.jar Jmeter 要链接MySQL数据库,首选需要下载mysql jdbc驱动包(注:驱动包的版本一定要与你 ...

  10. Log4net使用(二)

    转:http://www.cnblogs.com/basilwang/archive/2006/06/09/421868.html Log4net同时按照日期和大小生成RollingFile和访问Sy ...