标志位 last break
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的更多相关文章
- c语言数据结构:用标志位实现循环队列
#include<stdio.h> #include<stdlib.h> #define MAXSIZE 10//定义队列长度 ;//定义标志位 typedef struct ...
- 登录操作(方法一:设置flag标志位)
登录操作(方法一:设置flag标志位) user_name="star"passwoed='123'passed_authentication=Falsecount=0for i ...
- python基础知识--标志位的设定
在单层循环的退出中,使用break即能退出,那么多层循环呢?机智的人们使用flag标识符的方式,例如: exit_flag = False for i in range(10): if i <5 ...
- Java学习笔记14---使用标志位控制循环
使用标志位控制循环 前面提到了控制循环的常用技术:计数器控制的循环.另一种控制循环的常用技术是在读取和处理一个集合的值时指派一个特殊值.这个特殊的输入值也成为标志值(sentinel value),用 ...
- 汇编语言标志位 含义 NV UP EI NG NZ AC PE CY
缩写原意: Overflow of = OV NV [No Overflow] Direction df = DN (decrement) UP (increment) Interrupt if = ...
- STM32 串口固件库中定义的几个中断标志位什么意思?
在stm32f10x_usart.h中以上几个宏,很没有规律,诈一看还真不知道为什么会这么定义,其实通过代码就很容易明白: D7~D5:代表中断标志位对应的中断使能位在 CR1.CR2还是CR3寄存器 ...
- 【.net程序破解】实战之标志位破解绕过注册法
今天有时间玩了下一个不错的软件Advanced System Cleaner,可惜要注册 于是想办法给破解了,这是跟之前不同的地方,属于.NET破解教程: 软件地址 - http://www.crsk ...
- 除了创建时指定窗口位置之外,还有3种移动窗口位置的办法(移动的同时往往可以改变窗口大小)(SetWindowPos最有用,它有许多标志位)
首先,在创立窗口对象的时候,CreateWindowEx就可以指定窗口的位置.除此之外,还有三种方法可以改变窗口的位置: procedure TWinControl.CreateWindowHandl ...
- 内核参数优化之2-1 tcp/ip 标志位报文解析
以下内容纯属虚构,切勿轻易相信! 众所周知,tcp/ip三次握手和四次挥手,均由syn/ack/fin三个标志位报文决定,但是这三个标志位报文,并不是说在构建连接的时候只发送一次的,因为协议不知道网络 ...
随机推荐
- JavaScript基础入门教程(五)
说明 本系列博客的第一篇已经说明了,要求阅读者需要具有其它语言的编程基础,所以关于组数的基础部分本篇博客将不再赘述,主要讲js中数组的特性. 创建数组 数组的创建主要有两种方法,一种是数组直接量,还有 ...
- 分公司下拉框赋值-从后台传到前端jsp
我的旧代码 List<MetaBranchCfg> list = metaBranchCfgBO.queryAllBranchList(); request.setAttribute( ...
- Maven项目管理:SpringMVC+Mybatis+Velocity整合笔记
Maven创建项目 略…具体过程可参考用Maven创建第一个web项目 配置Spring MVC 导入Spring MVC 需要的包在pom.xml 文件下加入: 123456789101112 &l ...
- 转-"进程android.process.acore已意外停止" 解决办法
运行手机虚拟机时,老是弹出这样的“android.process.acore“服务已意外停止,虽不影响正常使用,但终究影响心情.网上找的方案,按如下步骤操作,可以解决问题: 出现这个提示不用担心,并不 ...
- 逻辑回归Logistic Regression 之基础知识准备
0. 前言 这学期 Pattern Recognition 课程的 project 之一是手写数字识别,之二是做一个网站验证码的识别(鸭梨不小哇).面包要一口一口吃,先尝试把模式识别的经典问题—— ...
- ajax常用请求方式
1.JAVA @RequestMapping(value = "testAjax") @ResponseBody public Map<String, Object> ...
- shell 脚本中执行mysql语句
通过hash建表之后,表的数据量巨大2048,那怎么去验证表是否建成功呢? 逻辑生成表名这部分就不写了.只要能建表成功,这部分的脚本肯定是有的.那么怎么在shell中执行selec查询并返回呢 只要在 ...
- [转]SQLSERVER存储过程调用不同数据库的数据_存储过程中通过链接服务器访问远程服务器
本文转自:http://blog.csdn.net/nnaabbcc/article/details/7967761 存储过程调用不同数据库的数据 在存储过程调用不同数据库的数据该如何做,比如在存储过 ...
- PHP中 "{}" 大括号的用法和总结
在PHP中,大括号“{}”可以起到如下作用: 1.将多个独立语句合并为一个复合语句,例如 if ... else ...中经常如此使用 2.在变量间接引用中进行定界,避免歧义.例如 ${$my_var ...
- Java反转单链表
class Node { private int data; private Node nextNode; public Node(int data) { this.data = data; } pu ...