last-完成rewrite指令的处理,之后搜索对应的URI和location;
break-完成rewrite指令的外理
[root@web01 app]# cat /app/server/nginx/conf/vhosts/default.conf
server {
listen default_server;
server_name localhost;
root /app/www;
location / {
root /app/www/html;
index index.html index.htm;
rewrite "/x/t.html" /y/t.html break;
}
location /y/ {
root /app/www/html/other;
}
}
[root@web01 other]# tree /app/www/html/
/app/www/html/
├── index.html
├── other
│   └── y
│       └── t.html
└── y
    └── t.html 3 directories, 3 files
[root@web01 other]# cat /app/www/html/y/t.html
yyy
[root@web01 other]# cat /app/www/html/other/y/t.html
other----->last
[root@web01 other]#
[root@web01 app]# curl http://192.168.1.24/x/t.html
yyy

当请求/x/t.html,符合rewrite规则,所以进行调整,调整的地址为/y/t.html,由于使用的flag是break,所以在 “location /”中进行跳转,结果是/app/www/html/y/t.html。但如果flag为last,那么/y/t.html将在"server"标签中重新执 行,由于存在一个“location /y/”,所以跳转被重新指定到“location /y/”标签,所以这个时候的结果为/app/www/html/other/y/t.html

如下测式:

[root@web01 other]# cat /app/www/html/other/y/t.html
other----->last
[root@web01 other]# cat /app/server/nginx/conf/vhosts/default.conf
server {
listen default_server;
server_name localhost;
root /app/www;
location / {
root /app/www/html;
index index.html index.htm;
#rewrite "/x/t.html" /y/t.html break;
rewrite "/x/t.html" /y/t.html last;#注意这里已经改成last
}
location /y/ {
root /app/www/html/other;
}
}
[root@web01 other]# curl http://192.168.1.24/x/t.html
other----->last

注意:使用last,如果配置不当,可能引起死循环。

[root@web01 www]# cat /app/server/nginx/conf/vhosts/default.conf
server {
listen default_server;
server_name localhost;
root /app/www;
location / {
rewrite /last/ /q.html last;#是相对于root /app/www 所以真实的访问路径是 /app/www/q.html
rewrite /break/ /q.html break;
}
location =/q.html {
return ;
}
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
include fastcgi.conf;
}
access_log /app/log/nginx/access/default.log;
}
[root@web01 www]# tree /app/www/
/app/www/
├── index.php
└── q.html directories, files
[root@web01 www]# cat /app/www/q.html
clnking@.com
[root@web01 www]# curl 192.168.1.24/last/q.html
<html>
<head><title> Bad Request</title></head>
<body bgcolor="white">
<center><h1> Bad Request</h1></center>
<hr><center>nginx/1.4.</center>
</body>
</html>
[root@web01 www]# curl 192.168.1.24/break/q.html
clnking@.com
  • last一般写在server和if中,而break一般使用在location中
  • last不终止重写后的url匹配,即新的url会再从server走一遍匹配流程,而break终止重写后的匹配
  • break和last都能组织继续执行后面的rewrite指令

location里一旦返回break则直接生效并停止后续的匹配location

server {
location / {
rewrite /last/ /q.html last;
rewrite /break/ /q.html break;
} location = /q.html {
return 400;
}
}
  • 访问/last/时重写到/q.html,然后使用新的uri再匹配,正好匹配到locatoin = /q.html然后返回了400
  • 访问/break时重写到/q.html,由于返回了break,则直接停止了.

标志位 last break的更多相关文章

  1. c语言数据结构:用标志位实现循环队列

    #include<stdio.h> #include<stdlib.h> #define MAXSIZE 10//定义队列长度 ;//定义标志位 typedef struct ...

  2. 登录操作(方法一:设置flag标志位)

    登录操作(方法一:设置flag标志位) user_name="star"passwoed='123'passed_authentication=Falsecount=0for i ...

  3. python基础知识--标志位的设定

    在单层循环的退出中,使用break即能退出,那么多层循环呢?机智的人们使用flag标识符的方式,例如: exit_flag = False for i in range(10): if i <5 ...

  4. Java学习笔记14---使用标志位控制循环

    使用标志位控制循环 前面提到了控制循环的常用技术:计数器控制的循环.另一种控制循环的常用技术是在读取和处理一个集合的值时指派一个特殊值.这个特殊的输入值也成为标志值(sentinel value),用 ...

  5. 汇编语言标志位 含义 NV UP EI NG NZ AC PE CY

    缩写原意: Overflow of = OV NV [No Overflow] Direction df = DN (decrement) UP (increment) Interrupt if = ...

  6. STM32 串口固件库中定义的几个中断标志位什么意思?

    在stm32f10x_usart.h中以上几个宏,很没有规律,诈一看还真不知道为什么会这么定义,其实通过代码就很容易明白: D7~D5:代表中断标志位对应的中断使能位在 CR1.CR2还是CR3寄存器 ...

  7. 【.net程序破解】实战之标志位破解绕过注册法

    今天有时间玩了下一个不错的软件Advanced System Cleaner,可惜要注册 于是想办法给破解了,这是跟之前不同的地方,属于.NET破解教程: 软件地址 - http://www.crsk ...

  8. 除了创建时指定窗口位置之外,还有3种移动窗口位置的办法(移动的同时往往可以改变窗口大小)(SetWindowPos最有用,它有许多标志位)

    首先,在创立窗口对象的时候,CreateWindowEx就可以指定窗口的位置.除此之外,还有三种方法可以改变窗口的位置: procedure TWinControl.CreateWindowHandl ...

  9. 内核参数优化之2-1 tcp/ip 标志位报文解析

    以下内容纯属虚构,切勿轻易相信! 众所周知,tcp/ip三次握手和四次挥手,均由syn/ack/fin三个标志位报文决定,但是这三个标志位报文,并不是说在构建连接的时候只发送一次的,因为协议不知道网络 ...

随机推荐

  1. 高并发场景系列(一) 利用redis实现分布式事务锁,解决高并发环境下减库存

    原文:http://blog.csdn.net/heyewu4107/article/details/71009712 高并发场景系列(一) 利用redis实现分布式事务锁,解决高并发环境下减库存 问 ...

  2. C++多重继承二义性解决

    1. 什么是多重继承的二义性 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class A{ public:     void f(); }   class B{ pu ...

  3. Oracle错误代码ORA-01653,表空间容量无法扩展

    业务模块在进行增操作时,报错“Caused by: java.sql.BatchUpdateException: ORA-01653: 表 JAZZ_V3.T_MZ_BK 无法通过 128 (在表空间 ...

  4. JS isNaN()函数

    1.作用 isNaN() 函数用于检查其参数是否是非数字值. 2.JS <script> document.write(isNaN(123)); document.write(isNaN( ...

  5. 吐血整理 Delphi系列书籍 118本(全)

    Delphi 教程 系列书籍 网友(老帅)整理 001_<Delhpi6数据库设计思想与实践> 002_<Delphi6应用开发指南> 003_<Delphi6开发人员指 ...

  6. Delphi控件开发浅入深出(三)

    三.开关控件TlincoSwitch 用过Delphi1(好古老的东东呀!)的人相信都记得这个开关控件 ,不知道当初Borland为什么把这么一个在开发普通应用程序中应用不到的工控控件放到Delphi ...

  7. fragment shader的优化

    ALU: 浮点数精度 选择性降低 shader 指令数 替换一些计算减小指令sqrt, sin, cos, recip 光照 计算用lightmap(用memory sample换计算) vertex ...

  8. Android-经常涉及到的权限

    Android中配置权限的方法: 在AndroidMainFest.xml中加上以下代码 Android中一些经常涉及到的权限: 添加WiFi以及访问网络的权限: <uses-permissio ...

  9. Lidgren.Network – an introduction to networking in C# games

    Lidgren.Network – an introduction to networking in C# games http://genericgamedev.com/tutorials/lidg ...

  10. jstat的用法

    转载:http://www.51testing.com/html/92/77492-203728.html 用以判断JVM是否存在内存问题呢?如何判断JVM垃圾回收是否正常?一般的top指令基本上满足 ...