Hi,
最近在学习Nginx的Lua模块,在测试ngx.req.set_uri的时候,发现了一些问题,
不理解为何如此,还望agentzh帮忙看 下。
我在测试lua的内部跳转,并和nginx的rewrite模块做对比,以下是我的配置文件:
location / {
default_type text/html;
add_header "Content" "text/html; charset=utf8";
rewrite ^/(.+)$ $1;
rewrite_by_lua '
ngx.req.set_uri("parseUri", true)
';
#rewrite . parseUri last;
}
location parseUri {
echo $uri;
}
在我使用lua来做内部跳转之前,我还有一个uri的rewrite,当我使用lua来做内部
跳转的时候,
root@pc-lx203:/var/log/nginx$ curl -i http://localhost/ccd
HTTP/1.1 404 Not Found
Server: ngx_openresty/1.0.15.10
Date: Tue, 26 Jun 2012 02:15:09 GMT
Content-Type: text/html
Content-Length: 180
Connection: keep-alive
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>ngx_openresty/1.0.15.10</center>
</body>
</html>
从上面的输出来看,没有进入到parseUri这个location。
但是如果我注释掉lua脚本的部分,使用nginx的rewrite模块来做内部跳转,
root@pc-lx203:/var/log/nginx$ curl -i http://localhost/ccd
HTTP/1.1 200 OK
Server: ngx_openresty/1.0.15.10
Date: Tue, 26 Jun 2012 02:17:12 GMT
Content-Type: application/octet-stream
Transfer-Encoding: chunked
Connection: keep-alive
parseUri
从lua的文档上来看,ngx.req.set_uri("parseUri", true) 是相当于nginx的
rewrite ^ parseUri last的,但是我不知道为什么这里的跳转上确实截然不同的
结果。
谢谢!