Welcome! Log In Create A New Profile

Advanced

[ANN] ngx_lua v0.1.1: access_by_lua and access_by_lua_file landed

agentzh
January 07, 2011 06:48AM
Hi, folks!

After the first public release of ngx_lua, I'm proud to annouce the
v0.1.1 version, which has introduced the access_by_lua and
access_by_lua_file directives:

https://github.com/chaoslawful/lua-nginx-module/tarball/v0.1.1

Now we can code up our own nginx access-phase handlers directly in
pure Lua, with all the capabilities with rewrite_by_lua and
content_by_lua, like firing up subrequests to other locations,
reading/writing nginx variables, changing response headers, internal
redirection, HTTP 301/302 redirection, throwing out 403/500/etc error
pages, and etc etc etc.

Here's a small example that emulates ngx_auth_request's functionality
in pure Lua:

location / {
access_by_lua '
local res = ngx.location.capture("/auth")
if res.status == ngx.HTTP_OK then
return
end
if res.status == ngx.HTTP_FORBIDDEN then
ngx.exit(res.status)
end
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
';

# proxy_pass/fastcgi_pass/postgres_pass/...
}

which is approximately equivalent to

location / {
auth_request /auth;

# proxy_pass/fastcgi_pass/postgres_pass/...
}

except that "auth_request" runs at the beginning of the nginx access
phase while "access_by_lua" runs at the end of the access phase.

ngx_lua is an nginx C module that embeds the Lua or LuaJIT interpreter
into the nginx core and you can find the latest source code and the
complete documentation here

https://github.com/chaoslawful/lua-nginx-module

Enjoy!
-agentzh

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

[ANN] ngx_lua v0.1.1: access_by_lua and access_by_lua_file landed

agentzh January 07, 2011 06:48AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 109
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready