So is "rewrite_by_lua" also evil?
agentzh
agentzh at gmail.com
Sun Oct 16 11:11:05 UTC 2011
On Sun, Oct 16, 2011 at 12:29 PM, agentzh <agentzh at gmail.com> wrote:
> You can now do what the "rewrite" directive does in pure Lua since the
> latest ngx_lua v0.3.1rc13 release.
>
> Your previous example
>
> location @pretty_urls {
> rewrite ^/sometext/xyz\.html$ /abc.html last;
> rewrite_by_lua 'ngx.exec("@proxy");';
> }
>
> can be rewritten as
>
> location @pretty_urls {
> rewrite_by_lua '
> if ngx.var.uri == "/sometext/xyz.html" then
> return ngx.req.set_uri("/abc.html")
> end
> ngx.exec("@proxy");
> ';
> }
>
Sorry, I've changed my mind and changed the ngx.req.set_uri() API a
bit in ngx_lua v0.3.1rc14. Now it's required to trigger location jump
explicitly and the above example should be rewritten as
location @pretty_urls {
rewrite_by_lua '
if ngx.var.uri == "/sometext/xyz.html" then
-- the following function never returns
-- when the second ("jump") arg is true
ngx.req.set_uri("/abc.html", true)
end
ngx.exec("@proxy");
';
}
> See the documentation here for details:
> http://wiki.nginx.org/HttpLuaModule#ngx.req.set_uri
>
I've also updated the document accordingly. Sorry for the
inconvenience but I'd preserve the right to change APIs that haven't
been in any formal releases of my modules :)
Thanks!
-agentzh
P.S. ngx_lua v0.3.1rc14 has already been included in ngx_openresty
devel release 1.0.8.11: http://openresty.org/#Download
More information about the nginx
mailing list