nginx rewrite中last和break的区别
2014-04-14 15:38
513 查看
在实际配置中,有的地方用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都不能成功
#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时break和last
- nginx 中的 last 和 break 区别。。。真理总是一两句话
- Nginx中的rewrite指令(break,last,redirect,permanent)
- Nginx中的rewrite指令(break,last,redirect,permanent)
- nginx中rewrite模块break和last原理详解
- nginx rewrite break last
- nginx中的break与last指令区别
- Nginx配置文件的rewrite功能中break和last的差别
- 从源码角度理解nginx配置中last与break的区别
- nginx 中的break和last的区别
- nginx中rewrite模块break和last原理详解
- nginx中的break与last指令区别
- nginx中rewrite模块break和last原理详解
- Nginx配置中last和break及permanent和redirect的区别
- Nginx中的rewrite指令(break,last,redirect,permanent)
- nginx配置中last与break的区别(原创)
- nginx rewrite中last和break的区别
- Nginx与Apache的Rewrite规则的区别