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. Tomcat监控—Status页面

    原文:http://jingyan.baidu.com/article/925f8cb8f3d925c0dce05677.html 修改配置文件tomcat-users(该文件在Tomcat安装程序根 ...

  2. 【java】【多线程】等待开启的多个线程都执行完成,再做事情,怎么实现

    今天在controller中写一个接口用来测试模拟多个请求同时到达 下订单的情况, 怎么能有效保证高并发下的库存和销量的一致性呢?[具体实现方法:https://www.cnblogs.com/sxd ...

  3. 2014 linux

    [51CTO精选译文]每年大概12月前后,人们喜欢给出种种预测,预言他们认为未来一年技术界会出现什么样的变化.本文也不例外,只不过侧重介绍2014年值得关注的十大最受关注的Linux发行版(桌面版或移 ...

  4. [转]Getting started with SSIS - Part 10: Event Handling and Logging

    本文转自:http://beyondrelational.com/modules/12/tutorials/24/tutorials/9686/getting-started-with-ssis-pa ...

  5. TensorFlow------TFRecords的读取实例

    TensorFlow------TFRecords的读取实例: import os import tensorflow as tf # 定义cifar的数据等命令行参数 FLAGS = tf.app. ...

  6. 11g R2单实例手工建库

    官档地址:Administrator's Guide --->>>Creating and Configuring an Oracle Database--->>> ...

  7. Android轻量级的开源缓存框架ASimpleCache

    点击查看原文 先上方法调用,写最经常使用的.其它不一一写 保存数据: ACache mACache=ACache.get(this); mACache.put("数据名称", js ...

  8. 利用HTML5与jQuery技术创建一个简单的自动表单完成

    来源:GBin1.com 在线演示   在线下载 谷歌快速搜索自带大量自动完成插件——库中甚至还有一个附带的jQuery UI共享选项.然而今天我要寻找一个替代的解决方案.由DevBridge开发的j ...

  9. python错误处理/调试/单元测试/文档测试

    一.错误处理 1.错误处理 try: ... except Exception1: ... except Exception2: ... finally: ... 如果在try中发生错误,那么exce ...

  10. Android Studio修改项目名和包名

    为了提高开发效率,有时候需要使用现有的一些开源项目,记录一下自己修改项目名和包名的方法. 1.首先,修改包名(清单文件里找), ①展开所有包 ②选中想要修改的包,shift+F6(也可右键Refact ...