So is "rewrite_by_lua" also evil?

agentzh agentzh at gmail.com
Sun Oct 16 04:29:34 UTC 2011


On Sat, Oct 15, 2011 at 10:20 PM, Nginx User <nginx at nginxuser.net> wrote:
> Makes sense to stick to one given that each is independent of the other.
> Just so tempting/logical on the surface, when they all go into the
> same location block for instance, to try to pick and choose elements
> from each.
>

That's all what we dream about, but the reality of the nginx internals
are sad in various ways and have been preventing us from doing a lot
of fancy things without hacking or even patching :)

> In my example, the flags from rewrite with the single line syntax is
> nice, clear and familiar but it does not provide a native mechanism to
> jump to another specific location (perhaps Igor would consider
> allowing try_files to accept a single argument).
>

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");
        ';
    }

I think it's also clean and readable as compared to the "rewrite"
directive, but much more flexible.

See the documentation here for details:
http://wiki.nginx.org/HttpLuaModule#ngx.req.set_uri

> Anyway, learnt a bit more and I will like to say thank you very much
> for the work put in to the various weird and wonderful modules you
> have pushed out.
> The modules open up a huge amount of options and really take Nginx to
> another level.

Glad you like it! And thank YOU for reporting all these issues during
your adventure ;)

Thanks!
-agentzh



More information about the nginx mailing list