Rewrite lookup via MySQL table

agentzh agentzh at
Tue Aug 24 08:03:11 MSD 2010

On Tue, Aug 24, 2010 at 11:32 AM, agentzh <agentzh at> wrote:
>        location /conv-uid {
>            internal;
>            content_by_lua_file 'html/foo.lua';
>        }

Sorry, forgot to paste the contents of my html/foo.lua here, and it's
the essential glue:

    -- foo.lua
    local yajl = require('yajl')
    local seo_uri = ngx.var.my_uri
    local res = ngx.location.capture('/conv-mysql?' .. seo_uri)
    if (res.status ~= ngx.HTTP_OK) then
    res = yajl.to_value(res.body)
    if (not res or not res[1] or not res[1].url) then
    ngx.var.my_uri = res[1].url;

This piece of Lua code is mostly self-explanatory if you do know a little Lua ;)

Tests have shown that enabling LuaJIT 2.0 here won't make things
noticeably faster because we do not have enough Lua for JIT'ing ;)

Have fun!

More information about the nginx mailing list