nginx rewrite中last和break的区别
来源:互联网 发布:如何提高seo 编辑:程序博客网 时间:2024/04/28 10:48
在实际配置中,有的地方用last并不能工作,换成break就可以,其中的原理是对于根目录的理解有所区别,按我的测试结果大致是这样的。
#location / {
#proxy_pass http://www.shortjob.cn;
#alias /home/html/;
#root /home/html;
#rewrite "^/a/(.*)\.html$" /1.html last;
#}
在#location / { 配置里:
1、使用root指定源:使用last和break都可以
2、使用proxy_pass指定源:使用last和break都可以
3、使用alias指定源:必须使用last
在location /a/或使用正则的location ~ ^/a/里:
1、使用root指定源:使用last和break都可以
2、使用proxy_pass指定源:使用break和last结果有所区别
3、使用alias指定源:必须使用last
其中区别主要在proxy_pass这个标签上,再看看几个测试结果:
location / {
root /home/html;
}
location /sh/ {
proxy_pass http://www.shortjob.cn;
rewrite "^/sh/(.*)\.html$" /1.html last;
}
在这段配置里,使用last访问是可以访问到东西的,不过,它出来的结果是:/home/html/1.html;可我需要的是http://www.shortjob.cn/sh/1.html?使用break就可以了。
location / {
root /home/html;
}
location /sh/ {
proxy_pass http://www.shortjob.cn;
rewrite "^/sh/(.*)\.html$" /sh/1.html last;
}
在这段配置里,返回错误,因为last会重新发起请求匹配,所以造成了一个死循环,使用break就可以访问到http://www.shortjob.cn/sh/1.html。
所以,使用last会对server标签重新发起请求,而break就直接使用当前的location中的数据源来访问,要视情况加以使用。一般在非根的location中配置rewrite,都是用的break;而根的location使用last比较好,因为如果配置了fastcgi或代理访问jsp文件的话,在根location下用break是访问不到。测试到rewrite有问题的时候,也不妨把这两者换换试试。
至于使用alias时为什么必须用last,估计是nginx本身就限定了的,怎么尝试break都不能成功- nginx rewrite中last和break的区别
- nginx rewrite中last和break的区别
- nginx rewrite中last和break的区别
- Nginx rewrite last 和break区别
- nginx中rewrite模块break和last原理详解
- nginx中rewrite模块break和last原理详解
- nginx rewrite 指令last break区别
- nginx rewrite 指令last break区别
- 实例区分nginx location中rewrite的break与last
- nginx rewrite break last
- nginx rewrite规则之last和break
- Nginx配置文件的rewrite功能中break和last的差别
- nginx last和break 区别
- nginx rewrite规则flag参数 break和 last
- nginx配置中last与break的区别(原创)
- nginx 中的 last 和 break 区别。。。真理总是一两句话
- 从源码角度理解nginx配置中last与break的区别
- Nginx中的rewrite指令(break,last,redirect,permanent)
- C#读取excel工作表(sheet)中的内容-----采用名称的方法
- 手机软件开发管理过程中,如何采用敏捷开发模式
- 工作流感念
- ubuntu Eclipse 英文斜体乱码解决
- ubuntu 10.04 配置tftp
- nginx rewrite中last和break的区别
- Ubuntu 下用 Eclipse 编译调试 Android NDK 工程
- 信号截断、能量泄漏及窗函数
- 对未来十年科技公司的猜想
- C# xml 文件的读写 SAX实现
- Struts2 spring 多配置文件使用通配符
- Fix Your Timestep!(Box2D效果优化)
- 共享个很棒的vim配置
- 剑指offer第8题 旋转数组 九度OJ1386