现在的位置: 首页Nginx>正文
ngx_lua v0.1.1: access_by_lua and access_by_lua_file landed
2011年03月11日 Nginx ngx_lua v0.1.1: access_by_lua and access_by_lua_file landed已关闭评论 ⁄ 被围观 24,346 次+

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/downloads

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:

  1. location /
  2. {
  3. access_by_lua ‘
  4. local res = ngx.location.capture("/auth")
  5. if res.status == ngx.HTTP_OK then
  6. return
  7. end
  8. if res.status == ngx.HTTP_FORBIDDEN then
  9. ngx.exit(res.status)
  10. end
  11. ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
  12. ‘;
  13. # proxy_pass/fastcgi_pass/postgres_pass/…
  14. }

which is approximately equivalent to

  1. location /
  2. {
  3. auth_request /auth;
  4. # proxy_pass/fastcgi_pass/postgres_pass/…
  5. }

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!

本文地址:http://www.92csz.com/21/16.html
如非注明则为本站原创文章,欢迎转载。转载请注明转载自:moon's blog
 

抱歉!评论已关闭.