首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

Nginx关于Rewrite施行顺序详解.docx

2012-07-25 
Nginx关于Rewrite执行顺序详解.docx,client: 127.0.0.1, server: localhost, request: GET /aaa.htmlHTTP

Nginx关于Rewrite执行顺序详解.docx

,client: 127.0.0.1, server: localhost, request: "GET /aaa.htmlHTTP/1.1", host: "localhost:9090"

, client: 127.0.0.1, server: localhost, request:"GET /aaa.html HTTP/1.1", host: "localhost:9090"

, client: 127.0.0.1, server: localhost, request:"GET /aaa.html HTTP/1.1", host: "localhost:9090"

, client: 127.0.0.1, server: localhost, request:"GET /aaa.html HTTP/1.1", host: "localhost:9090"

, client: 127.0.0.1, server: localhost, request:"GET /aaa.html HTTP/1.1", host: "localhost:9090"

, client: 127.0.0.1, server: localhost, request:"GET /aaa.html HTTP/1.1", host: "localhost:9090"

, client: 127.0.0.1, server: localhost, request:"GET /aaa.html HTTP/1.1", host: "localhost:9090"

, client: 127.0.0.1, server: localhost, request:"GET /aaa.html HTTP/1.1", host: "localhost:9090"

, client: 127.0.0.1, server: localhost, request:"GET /aaa.html HTTP/1.1", host: "localhost:9090"

, client: 127.0.0.1, server: localhost,request: "GET /aaa.html HTTP/1.1", host: "localhost:9090"”体现了重新匹配location的流程。

,client: 127.0.0.1, server: localhost, request: "GET /aaa.htmlHTTP/1.1", host: "localhost:9090"

, client: 127.0.0.1, server: localhost, request:"GET /aaa.html HTTP/1.1", host: "localhost:9090"

, client:127.0.0.1, server: localhost, request: "GET /aaa.html HTTP/1.1",host: "localhost:9090"

??????? }??
??? ??? location? /ddd.html {
??????????? rewrite "^/ddd\.html$" /eee.html;
??????? }

简单伪代码描述下rewrite执行过程:

?

boolean match_finish = false;
int match_count = 0;
while(!match_finish && match_count < 10) {
??? ??? match_count ++;
??? (1)按编辑顺序执行server级的rewrite指令;
??? (2)按重写后的URI匹配location;
??? (3)
??? ??? String uri_before_location = uri;
??? ??? 按编辑顺序执行location级的rewrite指令;
??? ??? String uri_after_location = rewrite(uri);
??? ??? if(uri_before_location != uri_after_location) {
??? ??? ??? match_finish = false;??? ??? ???
??? ??? } else {
??? ??? ??? match_finish = true;
??? ??? }
??? ??? if(location rewrite has last flag) {
??? ??? ??? continue;//表示不执行后面的rewrite,直接进入下一次迭代
??? ??? }
??? ??? if(location rewrite has break flag) {
??? ??? ??? break;//表示不执行后面的rewrite,并退出循环迭代
??? ??? }
}
if(match_count <= 10) {
??? return HTTP_200;
} else {
??? return HTTP_500;
}

1 楼 tianxueer 2011-10-05   这一行有错误:while(!match_ok && match_count < 10) {

match_ok应该是match_finish吧? 2 楼 eyesmore 2011-10-11   看得很细 呵呵  改了  示意的 3 楼 dgww 2012-03-26   厉害,把break 和 last 说的如此透彻。只是排版嘛,哈哈,差劲 4 楼 ty173238 2012-05-08   我试了下 现在重新rewrite不会执行 server级别的了 只执行 location
nginx/1.0.11

热点排行