一、环境准备

资源文件创建

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. [BZOJ3236][AHOI2013]作业:树套树/莫队+分块

    分析 第一问随便搞,直接说第二问. 令原数列为\(seq\),\(pre_i\)为\(seq_i\)这个值上一个出现的位置,于是可以简化询问条件为: \(l \leq i \leq r\) \(a \ ...

  2. 利用python进行数据分析--pandas入门2

    随书练习,第五章  pandas入门2 # coding: utf-8 # In[1]: from pandas import Series,DataFrame import pandas as pd ...

  3. Springboot-H2DB

    为什么在Springboot中用H2DB 用Springboot开发需要连接数据库的程序的时候,使用H2DB作为内存数据库可以很方便的调试程序. 怎么用 1.加入依赖 <dependency&g ...

  4. yum命令查询详解

    一.列举包文件列出资源库中所有可以安装或更新的rpm包# yum list列出资源库中特定的可以安装或更新以及已经安装的rpm包# yum list perl           //列出名为perl ...

  5. JavaVM & JNIEnv

    JNIEnv提供了大多数的JNI函数.你的本地方法都会接收JNIEnv作为第一个参数.JNIEnv用于本地线程存储.因此,你不能在线程间共享同一个JNIEnv.如果一个代码段没有其他方式获取它自身线程 ...

  6. WPF 实现多语言支持

    WPF 多语言有各种实现方式.如 https://www.codeproject.com/Articles/35159/WPF-Localization-Using-RESX-Files,后来发现这个 ...

  7. 运行jar包shell脚本

    #!/bin/sh #该文件必须放在jar包的目录下,因为是以相对路径来运行的.不放jar包目录的话,可以直接在jar_name参数写绝对路径 #start 设置三个参数 #环境 profile=te ...

  8. 几种 MyBatis 增强插件

    1. mybatis-generator/mybatis-generator-gui 2. 通用mapper 3. mybatis-plus 4. fastmybatis 5. mybatis-enh ...

  9. centos 6.5 升级openssh-7.5

    1.环境 2.安装telnet 服务,防止ssh升级之后登陆不上服务器,使用telnet 连接服务器 yum install telnet-server -y chkconfig telnet on ...

  10. laravel使用artisan报错SQLSTATE[42S02]: Base table or view not found: 1146

    说明你在应用初始化阶段使用到了数据库层面的东西,然而当时数据库不存在这个表/字段,所以会报错 需要在初始化比如 config 目录配置中,使用了数据库,在使用前需要添加一层判断,如果不存在 你需要用到 ...