标志位 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三个标志位报文决定,但是这三个标志位报文,并不是说在构建连接的时候只发送一次的,因为协议不知道网络 ...
随机推荐
- python中出现 “'gbk' codec can't decode byte 0xf3 in position 20: illegal multibyte sequence”问题
其实是打开文件方法open()中的模式有r,w,a等. 请看: r 以只读方式打开文件.文件的指针将会放在文件的开头.这是默认模式. rb 以二进制格式打开一个文件用于只读.文件指针将会放在文件的开头 ...
- Shell合并两个文件成一个文件的两列paste,awk
Shell合并两个文件成一个文件的两列 发布时间:2014-07-20 编辑:www.jquerycn.cn Shell合并两个文件成一个文件的两列,提供了两种方法,普通shell脚本,awk脚本 ...
- 在linux中实现多网卡的绑定 介绍常见的7种Bond模式
网卡bond是通过把多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡.在应用部署中是一种常用的技术,我们公司基本所有的项目相关服务器都做了bond,这里总结整理,以便待查. bond ...
- 理解Vue的状态管理模式Vuex
Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化. 状态管理模式.集中式存储管理,一听就很高大 ...
- http://blog.csdn.net/zxl315/article/details/10830105
http://blog.csdn.net/zxl315/article/details/10830105
- [Python爬虫] 之三十:Selenium +phantomjs 利用 pyquery抓取栏目
一.介绍 本例子用Selenium +phantomjs爬取栏目(http://tv.cctv.com/lm/)的信息 二.网站信息 三.数据抓取 首先抓取所有要抓取网页链接,共39页,保存到数据库里 ...
- 转: 学ppt的网址与素材
转:http://www.jianshu.com/p/89b261e0b8f6 你说你要学ppt,可你知道这些吗? 之前身边的同学总说做PPT很难,每次做ppt都头疼,我都对此很不屑,直到前一段开 ...
- [Functional Programming ADT] Initialize Redux Application State Using The State ADT
Not only will we need to give our initial state to a Redux store, we will also need to be able to re ...
- FTP服务器高级配置
设置FTP服务器的访问限制 /etc/vsftpd/ftpusers ftpusers :黑名单 其内所有的用户无法登录FTP服务器 如果userlist_enable=YES(主配置文件中设置),u ...
- js调试工具console方法详解
一.显示信息的方法 最常用的console.log(),一般用来调试. console.log('hello'); console.info('信息'); console.error('错误'); c ...