From e68990083ebdfb43a11341fa2c203710b2422547 Mon Sep 17 00:00:00 2001 From: Cyril Lavier Date: Wed, 12 Dec 2012 11:32:35 +0100 Subject: [PATCH] Updated nginx-lua with the 0.7.8 version. --- debian/modules/README.Modules-versions | 2 +- debian/modules/nginx-lua/.gitignore | 157 + debian/modules/nginx-lua/.gitmodules | 3 + debian/modules/nginx-lua/README | 2524 ++++++++++++----- debian/modules/nginx-lua/README.markdown | 1795 +++++++++--- debian/modules/nginx-lua/config | 117 +- .../modules/nginx-lua/doc/HttpLuaModule.wiki | 1760 +++++++++--- .../nginx-lua/dtrace/ngx_lua_provider.d | 61 + .../nginx-lua/src/api/ngx_http_lua_api.h | 23 +- .../nginx-lua/src/ngx_http_lua_accessby.c | 102 +- .../modules/nginx-lua/src/ngx_http_lua_api.c | 49 +- .../modules/nginx-lua/src/ngx_http_lua_args.c | 9 +- .../nginx-lua/src/ngx_http_lua_bodyfilterby.c | 627 ++++ .../nginx-lua/src/ngx_http_lua_bodyfilterby.h | 31 + .../nginx-lua/src/ngx_http_lua_cache.c | 19 +- .../src/ngx_http_lua_capturefilter.c | 43 +- .../nginx-lua/src/ngx_http_lua_clfactory.c | 646 ++++- .../nginx-lua/src/ngx_http_lua_common.h | 260 +- .../modules/nginx-lua/src/ngx_http_lua_conf.c | 210 -- .../modules/nginx-lua/src/ngx_http_lua_conf.h | 15 - .../nginx-lua/src/ngx_http_lua_contentby.c | 189 +- .../nginx-lua/src/ngx_http_lua_control.c | 179 +- .../nginx-lua/src/ngx_http_lua_coroutine.c | 331 +++ .../nginx-lua/src/ngx_http_lua_coroutine.h | 17 + .../modules/nginx-lua/src/ngx_http_lua_ctx.c | 19 +- .../nginx-lua/src/ngx_http_lua_directive.c | 273 +- .../nginx-lua/src/ngx_http_lua_directive.h | 27 +- .../nginx-lua/src/ngx_http_lua_exception.c | 30 +- .../src/ngx_http_lua_headerfilterby.c | 113 +- .../src/ngx_http_lua_headerfilterby.h | 3 + .../nginx-lua/src/ngx_http_lua_headers.c | 116 +- .../nginx-lua/src/ngx_http_lua_headers.h | 2 +- .../nginx-lua/src/ngx_http_lua_headers_in.c | 114 +- .../nginx-lua/src/ngx_http_lua_initby.c | 81 + .../nginx-lua/src/ngx_http_lua_initby.h | 16 + .../modules/nginx-lua/src/ngx_http_lua_log.c | 60 +- .../nginx-lua/src/ngx_http_lua_logby.c | 266 ++ .../nginx-lua/src/ngx_http_lua_logby.h | 18 + .../modules/nginx-lua/src/ngx_http_lua_misc.c | 13 +- .../nginx-lua/src/ngx_http_lua_module.c | 424 ++- .../modules/nginx-lua/src/ngx_http_lua_ndk.c | 4 +- .../nginx-lua/src/ngx_http_lua_output.c | 183 +- .../nginx-lua/src/ngx_http_lua_output.h | 7 +- .../nginx-lua/src/ngx_http_lua_phase.c | 82 + .../nginx-lua/src/ngx_http_lua_phase.h | 11 + .../nginx-lua/src/ngx_http_lua_probe.h | 85 + .../nginx-lua/src/ngx_http_lua_regex.c | 180 +- .../nginx-lua/src/ngx_http_lua_req_body.c | 507 +++- .../nginx-lua/src/ngx_http_lua_req_method.c | 108 + .../nginx-lua/src/ngx_http_lua_req_method.h | 12 + .../nginx-lua/src/ngx_http_lua_rewriteby.c | 93 +- .../nginx-lua/src/ngx_http_lua_script.c | 2 + .../nginx-lua/src/ngx_http_lua_setby.c | 208 +- .../nginx-lua/src/ngx_http_lua_setby.h | 2 + .../nginx-lua/src/ngx_http_lua_shdict.c | 389 ++- .../nginx-lua/src/ngx_http_lua_shdict.h | 2 + .../nginx-lua/src/ngx_http_lua_sleep.c | 181 ++ .../nginx-lua/src/ngx_http_lua_sleep.h | 11 + ...lua_socket.c => ngx_http_lua_socket_tcp.c} | 1309 ++++++--- ...lua_socket.h => ngx_http_lua_socket_tcp.h} | 50 +- .../nginx-lua/src/ngx_http_lua_socket_udp.c | 1486 ++++++++++ .../nginx-lua/src/ngx_http_lua_socket_udp.h | 49 + .../nginx-lua/src/ngx_http_lua_string.c | 21 +- .../nginx-lua/src/ngx_http_lua_subrequest.c | 527 +++- .../nginx-lua/src/ngx_http_lua_subrequest.h | 17 +- .../modules/nginx-lua/src/ngx_http_lua_time.c | 31 +- .../modules/nginx-lua/src/ngx_http_lua_time.h | 2 +- .../modules/nginx-lua/src/ngx_http_lua_uri.c | 74 +- .../nginx-lua/src/ngx_http_lua_uthread.c | 184 ++ .../nginx-lua/src/ngx_http_lua_uthread.h | 29 + .../modules/nginx-lua/src/ngx_http_lua_util.c | 2274 ++++++++++----- .../modules/nginx-lua/src/ngx_http_lua_util.h | 118 +- .../nginx-lua/src/ngx_http_lua_variable.c | 7 +- debian/modules/nginx-lua/t/.gitignore | 2 + debian/modules/nginx-lua/t/001-set.t | 493 +++- debian/modules/nginx-lua/t/002-content.t | 24 + debian/modules/nginx-lua/t/005-exit.t | 79 +- debian/modules/nginx-lua/t/009-log.t | 55 +- debian/modules/nginx-lua/t/014-bugs.t | 171 +- debian/modules/nginx-lua/t/015-status.t | 24 +- debian/modules/nginx-lua/t/016-resp-header.t | 44 +- debian/modules/nginx-lua/t/017-exec.t | 36 +- debian/modules/nginx-lua/t/018-ndk.t | 54 +- debian/modules/nginx-lua/t/020-subrequest.t | 656 ++++- debian/modules/nginx-lua/t/022-redirect.t | 25 +- .../nginx-lua/t/023-rewrite/client-abort.t | 850 ++++++ debian/modules/nginx-lua/t/023-rewrite/exit.t | 65 +- .../nginx-lua/t/023-rewrite/on-abort.t | 663 +++++ .../nginx-lua/t/023-rewrite/redirect.t | 2 - .../nginx-lua/t/023-rewrite/req-body.t | 2 +- .../nginx-lua/t/023-rewrite/req-socket.t | 536 ++++ .../modules/nginx-lua/t/023-rewrite/sleep.t | 223 ++ .../t/023-rewrite/socket-keepalive.t | 986 +++++++ .../t/023-rewrite/tcp-socket-timeout.t | 611 ++++ .../nginx-lua/t/023-rewrite/tcp-socket.t | 2038 +++++++++++++ .../nginx-lua/t/023-rewrite/unix-socket.t | 152 + .../nginx-lua/t/023-rewrite/uthread-exec.t | 352 +++ .../nginx-lua/t/023-rewrite/uthread-exit.t | 1353 +++++++++ .../t/023-rewrite/uthread-redirect.t | 195 ++ .../nginx-lua/t/023-rewrite/uthread-spawn.t | 1527 ++++++++++ .../nginx-lua/t/024-access/client-abort.t | 851 ++++++ debian/modules/nginx-lua/t/024-access/exit.t | 37 +- .../modules/nginx-lua/t/024-access/on-abort.t | 663 +++++ .../modules/nginx-lua/t/024-access/redirect.t | 2 - .../modules/nginx-lua/t/024-access/req-body.t | 2 +- debian/modules/nginx-lua/t/024-access/sleep.t | 223 ++ .../nginx-lua/t/024-access/uthread-exec.t | 352 +++ .../nginx-lua/t/024-access/uthread-exit.t | 1353 +++++++++ .../nginx-lua/t/024-access/uthread-redirect.t | 195 ++ .../nginx-lua/t/024-access/uthread-spawn.t | 1189 ++++++++ debian/modules/nginx-lua/t/025-codecache.t | 26 +- debian/modules/nginx-lua/t/026-mysql.t | 6 +- .../modules/nginx-lua/t/027-multi-capture.t | 47 +- debian/modules/nginx-lua/t/028-req-header.t | 540 +++- debian/modules/nginx-lua/t/030-uri-args.t | 97 +- debian/modules/nginx-lua/t/034-match.t | 28 +- debian/modules/nginx-lua/t/035-gmatch.t | 110 +- debian/modules/nginx-lua/t/037-gsub.t | 186 +- .../modules/nginx-lua/t/041-header-filter.t | 393 ++- debian/modules/nginx-lua/t/043-shdict.t | 298 +- debian/modules/nginx-lua/t/044-req-body.t | 582 +++- debian/modules/nginx-lua/t/055-subreq-vars.t | 28 +- debian/modules/nginx-lua/t/056-flush.t | 100 +- .../modules/nginx-lua/t/057-flush-timeout.t | 168 +- debian/modules/nginx-lua/t/058-tcp-socket.t | 97 +- debian/modules/nginx-lua/t/059-unix-socket.t | 10 +- .../modules/nginx-lua/t/060-lua-memcached.t | 1 - debian/modules/nginx-lua/t/061-lua-redis.t | 140 +- debian/modules/nginx-lua/t/062-count.t | 40 +- .../nginx-lua/t/065-tcp-socket-timeout.t | 208 +- .../nginx-lua/t/066-socket-receiveuntil.t | 91 +- debian/modules/nginx-lua/t/067-req-socket.t | 56 +- .../nginx-lua/t/068-socket-keepalive.t | 635 ++++- debian/modules/nginx-lua/t/069-null.t | 4 +- debian/modules/nginx-lua/t/071-idle-socket.t | 13 +- .../modules/nginx-lua/t/072-conditional-get.t | 14 +- debian/modules/nginx-lua/t/073-backtrace.t | 30 +- debian/modules/nginx-lua/t/075-logby.t | 520 ++++ debian/modules/nginx-lua/t/077-sleep.t | 214 ++ debian/modules/nginx-lua/t/078-hup-vars.t | 65 + .../nginx-lua/t/079-unused-directives.t | 262 ++ debian/modules/nginx-lua/t/080-hup-shdict.t | 85 + debian/modules/nginx-lua/t/081-bytecode.t | 229 ++ debian/modules/nginx-lua/t/082-body-filter.t | 485 ++++ .../modules/nginx-lua/t/083-bad-sock-self.t | 138 + .../nginx-lua/t/084-inclusive-receiveuntil.t | 747 +++++ debian/modules/nginx-lua/t/085-if.t | 202 ++ debian/modules/nginx-lua/t/086-init-by.t | 199 ++ debian/modules/nginx-lua/t/087-udp-socket.t | 654 +++++ debian/modules/nginx-lua/t/088-req-method.t | 227 ++ debian/modules/nginx-lua/t/089-phase.t | 139 + .../nginx-lua/t/090-log-socket-errors.t | 100 + debian/modules/nginx-lua/t/091-coroutine.t | 925 ++++++ debian/modules/nginx-lua/t/092-eof.t | 84 + .../modules/nginx-lua/t/093-uthread-spawn.t | 1675 +++++++++++ debian/modules/nginx-lua/t/094-uthread-exit.t | 1644 +++++++++++ debian/modules/nginx-lua/t/095-uthread-exec.t | 428 +++ .../nginx-lua/t/096-uthread-redirect.t | 282 ++ .../modules/nginx-lua/t/097-uthread-rewrite.t | 353 +++ debian/modules/nginx-lua/t/098-uthread-wait.t | 1225 ++++++++ debian/modules/nginx-lua/t/099-c-api.t | 363 +++ debian/modules/nginx-lua/t/100-client-abort.t | 922 ++++++ debian/modules/nginx-lua/t/101-on-abort.t | 790 ++++++ .../modules/nginx-lua/t/102-req-start-time.t | 117 + debian/modules/nginx-lua/t/StapThread.pm | 275 ++ debian/modules/nginx-lua/tapset/ngx_lua.stp | 5 + debian/modules/nginx-lua/util/build2.sh | 7 +- debian/modules/nginx-lua/util/gdbinit | 21 + debian/modules/nginx-lua/valgrind.suppress | 80 +- 169 files changed, 48115 insertions(+), 4369 deletions(-) create mode 100644 debian/modules/nginx-lua/.gitignore create mode 100644 debian/modules/nginx-lua/.gitmodules create mode 100644 debian/modules/nginx-lua/dtrace/ngx_lua_provider.d create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_bodyfilterby.c create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_bodyfilterby.h delete mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_conf.c delete mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_conf.h create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_coroutine.c create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_coroutine.h create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_initby.c create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_initby.h create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_logby.c create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_logby.h create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_phase.c create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_phase.h create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_probe.h create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_req_method.c create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_req_method.h create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_sleep.c create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_sleep.h rename debian/modules/nginx-lua/src/{ngx_http_lua_socket.c => ngx_http_lua_socket_tcp.c} (72%) rename debian/modules/nginx-lua/src/{ngx_http_lua_socket.h => ngx_http_lua_socket_tcp.h} (64%) create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_socket_udp.c create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_socket_udp.h create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_uthread.c create mode 100644 debian/modules/nginx-lua/src/ngx_http_lua_uthread.h create mode 100644 debian/modules/nginx-lua/t/.gitignore create mode 100644 debian/modules/nginx-lua/t/023-rewrite/client-abort.t create mode 100644 debian/modules/nginx-lua/t/023-rewrite/on-abort.t create mode 100644 debian/modules/nginx-lua/t/023-rewrite/req-socket.t create mode 100644 debian/modules/nginx-lua/t/023-rewrite/sleep.t create mode 100644 debian/modules/nginx-lua/t/023-rewrite/socket-keepalive.t create mode 100644 debian/modules/nginx-lua/t/023-rewrite/tcp-socket-timeout.t create mode 100644 debian/modules/nginx-lua/t/023-rewrite/tcp-socket.t create mode 100644 debian/modules/nginx-lua/t/023-rewrite/unix-socket.t create mode 100644 debian/modules/nginx-lua/t/023-rewrite/uthread-exec.t create mode 100644 debian/modules/nginx-lua/t/023-rewrite/uthread-exit.t create mode 100644 debian/modules/nginx-lua/t/023-rewrite/uthread-redirect.t create mode 100644 debian/modules/nginx-lua/t/023-rewrite/uthread-spawn.t create mode 100644 debian/modules/nginx-lua/t/024-access/client-abort.t create mode 100644 debian/modules/nginx-lua/t/024-access/on-abort.t create mode 100644 debian/modules/nginx-lua/t/024-access/sleep.t create mode 100644 debian/modules/nginx-lua/t/024-access/uthread-exec.t create mode 100644 debian/modules/nginx-lua/t/024-access/uthread-exit.t create mode 100644 debian/modules/nginx-lua/t/024-access/uthread-redirect.t create mode 100644 debian/modules/nginx-lua/t/024-access/uthread-spawn.t create mode 100644 debian/modules/nginx-lua/t/075-logby.t create mode 100644 debian/modules/nginx-lua/t/077-sleep.t create mode 100644 debian/modules/nginx-lua/t/078-hup-vars.t create mode 100644 debian/modules/nginx-lua/t/079-unused-directives.t create mode 100644 debian/modules/nginx-lua/t/080-hup-shdict.t create mode 100644 debian/modules/nginx-lua/t/081-bytecode.t create mode 100644 debian/modules/nginx-lua/t/082-body-filter.t create mode 100644 debian/modules/nginx-lua/t/083-bad-sock-self.t create mode 100644 debian/modules/nginx-lua/t/084-inclusive-receiveuntil.t create mode 100644 debian/modules/nginx-lua/t/085-if.t create mode 100644 debian/modules/nginx-lua/t/086-init-by.t create mode 100644 debian/modules/nginx-lua/t/087-udp-socket.t create mode 100644 debian/modules/nginx-lua/t/088-req-method.t create mode 100644 debian/modules/nginx-lua/t/089-phase.t create mode 100644 debian/modules/nginx-lua/t/090-log-socket-errors.t create mode 100644 debian/modules/nginx-lua/t/091-coroutine.t create mode 100644 debian/modules/nginx-lua/t/092-eof.t create mode 100644 debian/modules/nginx-lua/t/093-uthread-spawn.t create mode 100644 debian/modules/nginx-lua/t/094-uthread-exit.t create mode 100644 debian/modules/nginx-lua/t/095-uthread-exec.t create mode 100644 debian/modules/nginx-lua/t/096-uthread-redirect.t create mode 100644 debian/modules/nginx-lua/t/097-uthread-rewrite.t create mode 100644 debian/modules/nginx-lua/t/098-uthread-wait.t create mode 100644 debian/modules/nginx-lua/t/099-c-api.t create mode 100644 debian/modules/nginx-lua/t/100-client-abort.t create mode 100644 debian/modules/nginx-lua/t/101-on-abort.t create mode 100644 debian/modules/nginx-lua/t/102-req-start-time.t create mode 100644 debian/modules/nginx-lua/t/StapThread.pm create mode 100644 debian/modules/nginx-lua/tapset/ngx_lua.stp diff --git a/debian/modules/README.Modules-versions b/debian/modules/README.Modules-versions index d5e2646..f5a9db5 100644 --- a/debian/modules/README.Modules-versions +++ b/debian/modules/README.Modules-versions @@ -27,7 +27,7 @@ README for Modules versions nginx-lua Homepage: https://github.com/chaoslawful/lua-nginx-module https://github.com/chaoslawful/lua-nginx-module.git - Version: v0.5.0rc29-6446ee71b8 + Version: v0.7.8 nginx-upstream-fair Homepage: https://github.com/gnosek/nginx-upstream-fair diff --git a/debian/modules/nginx-lua/.gitignore b/debian/modules/nginx-lua/.gitignore new file mode 100644 index 0000000..a0bf9c3 --- /dev/null +++ b/debian/modules/nginx-lua/.gitignore @@ -0,0 +1,157 @@ +build/ +work/ +tags +cscope.* +*.mobi +genmobi.sh +.libs +*.swp +*.slo +*.la +*.swo +*.lo +*~ +*.o +print.txt +.rsync +*.tar.gz +dist +build[789] +build +tags +update-readme +*.tmp +test/Makefile +test/blib +test.sh +t.sh +t/t.sh +test/t/servroot/ +releng +reset +*.t_ +src/handler.h +src/util.c +src/module.h +src/module.c +src/drizzle.c +src/processor.h +src/handler.c +src/util.h +src/drizzle.h +src/processor.c +src/output.c +src/output.h +libdrizzle +ctags +src/stream.h +nginx +keepalive +reindex +src/keepalive.c +src/keepalive.h +src/checker.h +src/checker.c +src/quoting.h +src/quoting.c +src/module.h +src/module.c +src/util.h +src/util.c +src/processor.h +src/processor.c +src/rds.h +src/utils.h +src/handler.c +src/handler.h +util/bench +*.html +trace.out* +try.sh +src/cache.c +src/cache.h +src/common.h +src/directive.c +src/directive.h +src/consts.[ch] +src/contentby.[ch] +src/pcrefix.[ch] +src/util.c +src/clfactory.c +src/directive.c +src/conf.h +src/setby.h +src/cache.h +src/hook.c +src/util.h +src/hook.h +src/common.h +src/directive.h +src/conf.c +src/setby.c +src/cache.c +src/module.c +src/clfactory.h +src/capturefilter.[ch] +src/contentby.c +pack +b.sh +src/in.[ch] +src/out.[ch] +go +all.sh +src/accessby.[ch] +src/rewriteby.[ch] +src/patch.[ch] +src/ndk.[ch] +src/control.[ch] +src/output.[ch] +src/variable.[ch] +src/string.[ch] +src/misc.[ch] +src/log.[ch] +src/exception.[ch] +src/subrequest.[ch] +src/time.[ch] +src/regex.[ch] +src/ctx.[ch] +src/args.[ch] +src/headers.[ch] +src/script.[ch] +src/filter.[ch] +src/shdict.[ch] +src/body.[ch] +src/uri.[ch] +src/api.[ch] +src/coroutine.[ch] +src/logby.[ch] +src/sleep.[ch] +a.patch +all +build1[0-3] +g +buildroot/ +src/headerfilterby.[ch] +*.patch +analyze +tsock +a.c +test.lua +build12 +ERRORS +src/bodyfilterby.[ch] +src/tcp.[ch] +src/initby.[ch] +src/socket.[ch] +src/udp.[ch] +src/method.[ch] +tre +src/phase.[ch] +src/probe.h +src/uthread.[ch] +*.plist +lua +Makefile +tsubreq +tthread +addr2line diff --git a/debian/modules/nginx-lua/.gitmodules b/debian/modules/nginx-lua/.gitmodules new file mode 100644 index 0000000..db339a7 --- /dev/null +++ b/debian/modules/nginx-lua/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/ngx_devel_kit"] + path = deps/ngx_devel_kit + url = git://github.com/simpl/ngx_devel_kit.git diff --git a/debian/modules/nginx-lua/README b/debian/modules/nginx-lua/README index 49dfd2e..2e14c30 100644 --- a/debian/modules/nginx-lua/README +++ b/debian/modules/nginx-lua/README @@ -8,9 +8,9 @@ Status This module is under active development and is production ready. Version - This document describes ngx_lua v0.5.0rc28 - () released on 16 - May 2012. + This document describes ngx_lua v0.7.8 + () released on 8 + December 2012. Synopsis # set search paths for pure Lua external libraries (';;' is the default path): @@ -115,7 +115,7 @@ Synopsis location /foo { rewrite_by_lua ' res = ngx.location.capture("/memc", - { args = { cmd = 'incr', key = ngx.var.uri } } + { args = { cmd = "incr", key = ngx.var.uri } } ) '; @@ -160,7 +160,7 @@ Synopsis client_body_buffer_size 100k; access_by_lua ' - -- check the client IP addr is in our black list + -- check the client IP address is in our black list if ngx.var.remote_addr == "132.5.72.3" then ngx.exit(ngx.HTTP_FORBIDDEN) end @@ -180,27 +180,57 @@ Synopsis } Description - This module embeds Lua, via the standard Lua interpreter or LuaJIT, into - Nginx and by leveraging Nginx's subrequests, allows the integration of - the powerful Lua threads (Lua coroutines) into the Nginx event model. + This module embeds Lua, via the standard Lua interpreter or LuaJIT 2.0 + (), into Nginx and by leveraging Nginx's + subrequests, allows the integration of the powerful Lua threads (Lua + coroutines) into the Nginx event model. Unlike Apache's mod_lua () and Lighttpd's mod_magnet (), Lua code executed using this module can be *100% non-blocking* on network traffic as long as the Nginx API for Lua provided by this module is used - to handle requests to upstream services such as mysql, postgresql, - memcached, redis, or upstream http web services. (See - ngx.location.capture, ngx.location.capture_multi, ngx.socket.tcp, - [[HttpDrizzleModule]], ngx_postgres - (), [[HttpMemcModule]], - [[HttpRedis2Module]] and [[HttpProxyModule]] modules for details). + to handle requests to upstream services such as MySQL, PostgreSQL, + Memcached, Redis, or upstream HTTP web services. + + At least the following Lua libraries and Nginx modules can be used with + this ngx_lua module: + + * lua-resty-memcached + () + + * lua-resty-mysql () + + * lua-resty-redis () + + * lua-resty-dns () + + * lua-resty-upload () + + * ngx_memc + + * ngx_postgres () + + * ngx_redis2 + + * ngx_redis + + * ngx_proxy + + * ngx_fastcgi + + Almost all the Nginx modules can be used with this ngx_lua module by + means of ngx.location.capture or ngx.location.capture_multi but it is + recommended to use those "lua-resty-*" libraries instead of creating + subrequests to access the Nginx upstream modules because the former is + usually much more flexible and memory-efficient. The Lua interpreter or LuaJIT instance is shared across all the requests in a single nginx worker process but request contexts are segregated - using lightweight Lua coroutines. Loaded Lua modules persist in the - nginx worker process level resulting in a small memory footprint even - when under heavy loads. + using lightweight Lua coroutines. + + Loaded Lua modules persist in the nginx worker process level resulting + in a small memory footprint in Lua even when under heavy loads. Directives lua_code_cache @@ -220,9 +250,9 @@ Directives request (such that Lua modules will not be cached either). With this in place, developers can adopt an edit-and-refresh approach. - Please note however, that Lua code inlined into nginx.conf such as those - specified by set_by_lua, content_by_lua, access_by_lua, and - rewrite_by_lua will *always* be cached because only the Nginx config + Please note however, that Lua code written inlined within nginx.conf + such as those specified by set_by_lua, content_by_lua, access_by_lua, + and rewrite_by_lua will *always* be cached because only the Nginx config file parser can correctly parse the "nginx.conf" file and the only ways to to reload the config file are to send a "HUP" signal or to restart Nginx. @@ -275,7 +305,7 @@ Directives content_by_lua and others. The path string is in standard Lua path form, and ";;" can be used to stand for the original search paths. - Since the "v0.5.0rc29" release, the special notation $prefix or + As from the "v0.5.0rc29" release, the special notation $prefix or "${prefix}" can be used in the search path string to indicate the path of the "server prefix" usually determined by the "-p PATH" command-line option while starting the Nginx server. @@ -292,17 +322,114 @@ Directives set_by_lua, content_by_lua and others. The cpath string is in standard Lua cpath form, and ";;" can be used to stand for the original cpath. - Since the "v0.5.0rc29" release, the special notation $prefix or + As from the "v0.5.0rc29" release, the special notation $prefix or "${prefix}" can be used in the search path string to indicate the path of the "server prefix" usually determined by the "-p PATH" command-line option while starting the Nginx server. + init_by_lua + syntax: *init_by_lua * + + context: *http* + + phase: *loading-config* + + Runs the Lua code specified by the argument "" on the + global Lua VM level when the Nginx master process (if any) is loading + the Nginx config file. + + When Nginx receives the "HUP" signal and starts reloading the config + file, the Lua VM will also be re-created and "init_by_lua" will run + again on the new Lua VM. + + Usually you can register (true) Lua global variables or pre-load Lua + modules at server start-up by means of this hook. Here is an example for + pre-loading Lua modules: + + init_by_lua 'require "cjson"'; + + server { + location = /api { + content_by_lua ' + ngx.say(cjson.encode({dog = 5, cat = 6})) + '; + } + } + + You can also initialize the lua_shared_dict shm storage at this phase. + Here is an example for this: + + lua_shared_dict dogs 1m; + + init_by_lua ' + local dogs = ngx.shared.dogs; + dogs:set("Tom", 56) + '; + + server { + location = /api { + content_by_lua ' + local dogs = ngx.shared.dogs; + ngx.say(dogs:get("Tom")) + '; + } + } + + But note that, the lua_shared_dict's shm storage will not be cleared + through a config reload (via the "HUP" signal, for example). So if you + do *not* want to re-initialize the shm storage in your "init_by_lua" + code in this case, then you just need to set a custom flag in the shm + storage and always check the flag in your "init_by_lua" code. + + Because the Lua code in this context runs before Nginx forks its worker + processes (if any), data or code loaded here will enjoy the + Copy-on-write (COW) () + feature provided by many operating systems among all the worker + processes, thus saving a lot of memory. + + Only a small set of the Nginx API for Lua is supported in this context: + + * Logging APIs: ngx.log and print, + + * Shared Dictionary API: ngx.shared.DICT. + + More Nginx APIs for Lua may be supported in this context upon future + user requests. + + Basically you can safely use Lua libraries that do blocking I/O in this + very context because blocking the master process during server start-up + is completely okay. Even the Nginx core does blocking I/O (at least on + resolving upstream's host names) at the configure-loading phase. + + You should be very careful about potential security vulnerabilities in + your Lua code registered in this context because the Nginx master + process is often run under the "root" account. + + This directive was first introduced in the "v0.5.5" release. + + init_by_lua_file + syntax: *init_by_lua_file * + + context: *http* + + phase: *loading-config* + + Equivalent to init_by_lua, except that the file specified by + "" contains the Lua code or Lua/LuaJIT bytecode + to be executed. + + When a relative path like "foo/bar.lua" is given, they will be turned + into the absolute path relative to the "server prefix" path determined + by the "-p PATH" command-line option while starting the Nginx server. + + This directive was first introduced in the "v0.5.5" release. + set_by_lua syntax: *set_by_lua $res [$arg1 $arg2 ...]* - context: *main, server, location, server if, location if* + context: *server, server if, location, location if* - phase: *rewrite* + phase: *server-rewrite, rewrite* Executes code specified in "" with optional input arguments "$arg1 $arg2 ...", and returns string output to $res. The code @@ -314,8 +441,17 @@ Directives the Nginx event loop is blocked during code execution. Time consuming code sequences should therefore be avoided. - Note that I/O operations such as ngx.say, ngx.exec, echo and similar are - not permitted within the context of this directive. + Note that the following API functions are currently disabled within this + context: + + * Output API functions (e.g., ngx.say and ngx.send_headers) + + * Control API functions (e.g., ngx.exit) + + * Subrequest API functions (e.g., ngx.location.capture and + ngx.location.capture_multi) + + * Cosocket API functions (e.g., ngx.socket.tcp and ngx.req.socket). In addition, note that this directive can only write out a value to a single Nginx variable at a time. However, a workaround is possible using @@ -344,9 +480,9 @@ Directives set_by_lua $bar 'tonumber(ngx.var.foo) + 1'; set $baz "bar: $bar"; # $baz == "bar: 33" - Since the "0.5.0rc29" release, Nginx variable interpolation is disabled - in the "" argument of this directive, and you can use - the dollar sign character ("$") directly. + As from the "v0.5.0rc29" release, Nginx variable interpolation is + disabled in the "" argument of this directive and + therefore, the dollar sign character ("$") can be used directly. This directive requires the ngx_devel_kit () module. @@ -355,19 +491,20 @@ Directives syntax: *set_by_lua_file $res [$arg1 $arg2 ...]* - context: *main, server, location, server if, location if* + context: *server, server if, location, location if* - phase: *rewrite* + phase: *server-rewrite, rewrite* Equivalent to set_by_lua, except that the file specified by - "" contains the Lua code to be executed. + "" contains the Lua code, or, as from the + "v0.5.0rc32" release, the Lua/LuaJIT bytecode to be executed. Nginx variable interpolation is supported in the "" argument string of this directive. But special care must be taken for injection attacks. When a relative path like "foo/bar.lua" is given, they will be turned - into the absoluate path relative to the "server prefix" path determined + into the absolute path relative to the "server prefix" path determined by the "-p PATH" command-line option while starting the Nginx server. When the Lua code cache is turned on (by default), the user code is @@ -403,14 +540,15 @@ Directives phase: *content* Equivalent to content_by_lua, except that the file specified by - "" contains the Lua code to be executed. + "" contains the Lua code, or, as from the + "v0.5.0rc32" release, the Lua/LuaJIT bytecode to be executed. Nginx variables can be used in the "" string to provide flexibility. This however carries some risks and is not ordinarily recommended. When a relative path like "foo/bar.lua" is given, they will be turned - into the absoluate path relative to the "server prefix" path determined + into the absolute path relative to the "server prefix" path determined by the "-p PATH" command-line option while starting the Nginx server. When the Lua code cache is turned on (by default), the user code is @@ -490,7 +628,7 @@ Directives fastcgi_pass ...; } - can be implemented in "ngx_lua" as: + can be implemented in ngx_lua as: location = /check-spam { internal; @@ -501,7 +639,7 @@ Directives rewrite_by_lua ' local res = ngx.location.capture("/check-spam") if res.body == "spam" then - ngx.redirect("/terms-of-use.html") + return ngx.redirect("/terms-of-use.html") end '; @@ -535,9 +673,12 @@ Directives Here the Lua code "ngx.exit(503)" will never run. This will be the case if "rewrite ^ /bar last" is used as this will similarly initiate an internal redirection. If the "break" modifier is used instead, there - will be no internal redirection and the rewrite_by_lua code will be + will be no internal redirection and the "rewrite_by_lua" code will be executed. + The "rewrite_by_lua" code will always run at the end of the "rewrite" + request-processing phase unless rewrite_by_lua_no_postpone is turned on. + rewrite_by_lua_file syntax: *rewrite_by_lua_file * @@ -546,14 +687,15 @@ Directives phase: *rewrite tail* Equivalent to rewrite_by_lua, except that the file specified by - "" contains the Lua code to be executed. + "" contains the Lua code, or, as from the + "v0.5.0rc32" release, the Lua/LuaJIT bytecode to be executed. Nginx variables can be used in the "" string to provide flexibility. This however carries some risks and is not ordinarily recommended. When a relative path like "foo/bar.lua" is given, they will be turned - into the absoluate path relative to the "server prefix" path determined + into the absolute path relative to the "server prefix" path determined by the "-p PATH" command-line option while starting the Nginx server. When the Lua code cache is turned on (by default), the user code is @@ -562,6 +704,10 @@ Directives can be temporarily disabled during development by switching lua_code_cache "off" in "nginx.conf" to avoid reloading Nginx. + The "rewrite_by_lua_file" code will always run at the end of the + "rewrite" request-processing phase unless rewrite_by_lua_no_postpone is + turned on. + access_by_lua syntax: *access_by_lua * @@ -605,7 +751,7 @@ Directives # proxy_pass/fastcgi_pass/postgres_pass/... } - can be implemented in "ngx_lua" as: + can be implemented in ngx_lua as: location / { access_by_lua ' @@ -644,14 +790,15 @@ Directives phase: *access tail* Equivalent to access_by_lua, except that the file specified by - "" contains the Lua code to be executed. + "" contains the Lua code, or, as from the + "v0.5.0rc32" release, the Lua/LuaJIT bytecode to be executed. Nginx variables can be used in the "" string to provide flexibility. This however carries some risks and is not ordinarily recommended. When a relative path like "foo/bar.lua" is given, they will be turned - into the absoluate path relative to the "server prefix" path determined + into the absolute path relative to the "server prefix" path determined by the "-p PATH" command-line option while starting the Nginx server. When the Lua code cache is turned on (by default), the user code is @@ -669,16 +816,20 @@ Directives phase: *output-header-filter* Uses Lua code specified in "" to define an output header - filter. Note that the following API functions are currently disabled - within this context: + filter. + + Note that the following API functions are currently disabled within this + context: * Output API functions (e.g., ngx.say and ngx.send_headers) - * Control API functions (e.g., ngx.exit) + * Control API functions (e.g., ngx.exit and ngx.exec) * Subrequest API functions (e.g., ngx.location.capture and ngx.location.capture_multi) + * Cosocket API functions (e.g., ngx.socket.tcp and ngx.req.socket). + Here is an example of overriding a response header (or adding one if absent) in our Lua header filter: @@ -697,14 +848,212 @@ Directives phase: *output-header-filter* Equivalent to header_filter_by_lua, except that the file specified by - "" contains the Lua code to be executed. + "" contains the Lua code, or as from the + "v0.5.0rc32" release, the Lua/LuaJIT bytecode to be executed. When a relative path like "foo/bar.lua" is given, they will be turned - into the absoluate path relative to the "server prefix" path determined + into the absolute path relative to the "server prefix" path determined by the "-p PATH" command-line option while starting the Nginx server. This directive was first introduced in the "v0.2.1rc20" release. + body_filter_by_lua + syntax: *body_filter_by_lua * + + context: *http, server, location, location if* + + phase: *output-body-filter* + + Uses Lua code specified in "" to define an output body + filter. + + The input data chunk is passed via ngx.arg[1] (as a Lua string value) + and the "eof" flag indicating the end of the response body data stream + is passed via ngx.arg[2] (as a Lua boolean value). + + Behind the scene, the "eof" flag is just the "last_buf" flag of the + nginx chain link buffers. And in the context of an Nginx subrequest, + there is no "eof" flag at all, due to the underlying limitation in the + Nginx core. + + The output data stream can be aborted immediately by running the + following Lua statement: + + return ngx.ERROR + + This will truncate the response body and usually result in incomplete + and also invalid responses. + + The Lua code can pass its own modified version of the input data chunk + to the downstream Nginx output body filters by overriding ngx.arg[1] + with a Lua string or a Lua table of strings. For example, to transform + all the lowercase letters in the response body, we can just write: + + location / { + proxy_pass http://mybackend; + body_filter_by_lua 'ngx.arg[1] = string.upper(ngx.arg[1])'; + } + + When setting "nil" or an empty Lua string value to "ngx.arg[1]", no data + chunk will be passed to the downstream Nginx output filters at all. + + Likewise, new "eof" flag can also be specified by setting a boolean + value to ngx.arg[2]. For example, + + location /t { + echo hello world; + echo hiya globe; + + body_filter_by_lua ' + local chunk = ngx.arg[1] + if string.match(chunk, "hello") then + ngx.arg[2] = true -- new eof + return + end + + -- just throw away any remaining chunk data + ngx.arg[1] = nil + '; + } + + Then "GET /t" will just return the output + + hello world + + That is, when the body filter sees a chunk containing the word "hello", + then it will set the "eof" flag to true immediately, resulting in + truncated but still valid responses. + + When the Lua code may change the length of the response body, then it is + required to always clear out the "Content-Length" response header (if + any) in a header filter to enforce streaming output, as in + + location /foo { + # fastcgi_pass/proxy_pass/... + + header_filter_by_lua 'ngx.header.content_length = nil'; + body_filter_by_lua 'ngx.arg[1] = {string.len(arg[1]), "\n"}' + } + + Note that the following API functions are currently disabled within this + context: + + * Output API functions (e.g., ngx.say and ngx.send_headers) + + * Control API functions (e.g., ngx.exit and ngx.exec) + + * Subrequest API functions (e.g., ngx.location.capture and + ngx.location.capture_multi) + + * Cosocket API functions (e.g., ngx.socket.tcp and ngx.req.socket). + + Nginx output filters may be called multiple times for a single request + because response body may be delivered in chunks. Thus, the Lua code + specified by in this directive may also run multiple times in the + lifetime of a single HTTP request. + + This directive was first introduced in the "v0.5.0rc32" release. + + body_filter_by_lua_file + syntax: *body_filter_by_lua_file * + + context: *http, server, location, location if* + + phase: *output-body-filter* + + Equivalent to body_filter_by_lua, except that the file specified by + "" contains the Lua code, or, as from the + "v0.5.0rc32" release, the Lua/LuaJIT bytecode to be executed. + + When a relative path like "foo/bar.lua" is given, they will be turned + into the absolute path relative to the "server prefix" path determined + by the "-p PATH" command-line option while starting the Nginx server. + + This directive was first introduced in the "v0.5.0rc32" release. + + log_by_lua + syntax: *log_by_lua * + + context: *http, server, location, location if* + + phase: *log* + + Run the Lua source code inlined as the "" at the "log" + request processing phase. This does not replace the current access logs, + but runs after. + + Note that the following API functions are currently disabled within this + context: + + * Output API functions (e.g., ngx.say and ngx.send_headers) + + * Control API functions (e.g., ngx.exit) + + * Subrequest API functions (e.g., ngx.location.capture and + ngx.location.capture_multi) + + * Cosocket API functions (e.g., ngx.socket.tcp and ngx.req.socket). + + Here is an example of gathering average data for + $upstream_response_time: + + lua_shared_dict log_dict 5M; + + server { + location / { + proxy_pass http://mybackend; + + log_by_lua ' + local log_dict = ngx.shared.log_dict + local upstream_time = tonumber(ngx.var.upstream_response_time) + + local sum = log_dict:get("upstream_time-sum") or 0 + sum = sum + upstream_time + log_dict:set("upstream_time-sum", sum) + + local newval, err = log_dict:incr("upstream_time-nb", 1) + if not newval and err == "not found" then + log_dict:add("upstream_time-nb", 0) + log_dict:incr("upstream_time-nb", 1) + end + '; + } + + location = /status { + content_by_lua ' + local log_dict = ngx.shared.log_dict + local sum = log_dict:get("upstream_time-sum") + local nb = log_dict:get("upstream_time-nb") + + if nb and sum then + ngx.say("average upstream response time: ", sum / nb, + " (", nb, " reqs)") + else + ngx.say("no data yet") + end + '; + } + } + + This directive was first introduced in the "v0.5.0rc31" release. + + log_by_lua_file + syntax: *log_by_lua_file * + + context: *http, server, location, location if* + + phase: *log* + + Equivalent to log_by_lua, except that the file specified by + "" contains the Lua code, or, as from the + "v0.5.0rc32" release, the Lua/LuaJIT bytecode to be executed. + + When a relative path like "foo/bar.lua" is given, they will be turned + into the absolute path relative to the "server prefix" path determined + by the "-p PATH" command-line option while starting the Nginx server. + + This directive was first introduced in the "v0.5.0rc31" release. + lua_need_request_body syntax: *lua_need_request_body * @@ -724,8 +1073,8 @@ Directives client_body_buffer_size must have the same value as client_max_body_size. Because when the content length exceeds client_body_buffer_size but less than client_max_body_size, Nginx will - automatically buffer the data into a temporary file on the disk, which - will lead to empty value in the $request_body variable. + buffer the data into a temporary file on the disk, which will lead to + empty value in the $request_body variable. If the current location includes rewrite_by_lua or rewrite_by_lua_file directives, then the request body will be read just before the @@ -750,8 +1099,8 @@ Directives phase: *depends on usage* - Declares a shared memory zone, "", to serve as storage for the - shm-based Lua dictionary "ngx.shared.". + Declares a shared memory zone, "", to serve as storage for the shm + based Lua dictionary "ngx.shared.". The "" argument accepts size units such as "k" and "m": @@ -856,9 +1205,9 @@ Directives Default to 30 connections for every pool. - When the connection pool is exceeding the size limit, the least recently - used (idle) connection already in the pool will be closed automatically - to make room for the current connection. + When the connection pool exceeds the available size limit, the least + recently used (idle) connection already in the pool will be closed to + make room for the current connection. Note that the cosocket connection pool is per nginx worker process rather than per nginx server instance, so so size limit specified here @@ -875,15 +1224,30 @@ Directives This directive controls the default maximal idle time of the connections in the cosocket built-in connection pool. When this timeout reaches, - idle connections will be closed automatically and removed from the pool. - This setting can be overridden by cosocket objects' setkeepalive method. + idle connections will be closed and removed from the pool. This setting + can be overridden by cosocket objects' setkeepalive method. The "