http-lua #

OpenResty Lua module — embed full Lua/LuaJIT scripting into nginx for request handling, access control, traffic shaping, dynamic routing and almost anything else you can imagine.

Source: upstream source

Directives

access_by_lua #

syntax: access_by_lua 1 arg;  ·  context: http, server, location, location-if

Nginx variables are supported in the file path for dynamic dispatch just as in content_by_lua_file. Back to TOC access_by_lua ------------- syntax: access_by_lua <lua-script-str> context: http, server, location, location if phase: access tail NOTE Use of this directive is discouraged following the v0.9.17 release.

access_by_lua_block #

syntax: access_by_lua_block no args;  ·  context: http, server, location, location-if

Use the access_by_lua_block directive instead.

access_by_lua_file #

syntax: access_by_lua_file 1 arg;  ·  context: http, server, location, location-if

So the Lua files referenced in set_by_lua_file, content_by_lua_file, access_by_lua_file, and etc will not be cached and all Lua modules used will be loaded from scratch.

access_by_lua_no_postpone #

syntax: access_by_lua_no_postpone on | off (on/off flag);  ·  context: http

Starting from the v0.9.20 release, you can use the access_by_lua_no_postpone directive to control when to run this handler inside the "access" request-processing phase of Nginx.

balancer_by_lua_block #

syntax: balancer_by_lua_block no args;  ·  context: upstream

This directive was first introduced in the v0.5.0rc31 release. Back to TOC balancer_by_lua_block --------------------- syntax: balancer_by_lua_block { lua-script } context: upstream phase: content This directive runs Lua code as an upstream balancer for any upstream entities defined by the upstream {} configuration block.

balancer_by_lua_file #

syntax: balancer_by_lua_file 1 arg;  ·  context: upstream

Selects an upstream peer for the current request via Lua, loading code from an external file instead of an inline block.

balancer_keepalive #

syntax: balancer_keepalive 1 arg;  ·  context: upstream

Sets the maximum number of idle keepalive connections to upstream servers cached per worker process (default 32).

body_filter_by_lua #

syntax: body_filter_by_lua 1 arg;  ·  context: http, server, location, location-if

This directive was first introduced in the v0.2.1rc20 release. Back to TOC body_filter_by_lua ------------------ syntax: body_filter_by_lua <lua-script-str> context: http, server, location, location if phase: output-body-filter NOTE Use of this directive is discouraged following the v0.9.17 release.

body_filter_by_lua_block #

syntax: body_filter_by_lua_block no args;  ·  context: http, server, location, location-if

Use the body_filter_by_lua_block directive instead.

body_filter_by_lua_file #

syntax: body_filter_by_lua_file 1 arg;  ·  context: http, server, location, location-if

Filters response body chunks using Lua code loaded from a file, equivalent to body_filter_by_lua_block.

content_by_lua #

syntax: content_by_lua 1 arg;  ·  context: location, location-if

This directive was first introduced in the v0.8.5 release. Back to TOC lua_package_path ---------------- syntax: lua_package_path <lua-style-path-str> default: The content of LUA_PATH environment variable or Lua's compiled-in defaults. context: http Sets the Lua module search path used by scripts specified by set_by_lua, content_by_lua and others.

content_by_lua_block #

syntax: content_by_lua_block no args;  ·  context: location, location-if

Use the content_by_lua_block directive instead.

content_by_lua_file #

syntax: content_by_lua_file 1 arg;  ·  context: location, location-if

This directive was first introduced in the v0.10.7 release. Back to TOC lua_code_cache -------------- syntax: lua_code_cache on | off default: lua_code_cache on context: http, server, location, location if Enables or disables the Lua code cache for Lua code in *_by_lua_file directives (like set_by_lua_file and content_by_lua_file) and Lua modules.

exit_worker_by_lua_block #

syntax: exit_worker_by_lua_block no args;  ·  context: http

This hook no longer runs in the cache manager and cache loader processes since the v0.10.12 release. Back to TOC exit_worker_by_lua_block ------------------------ syntax: exit_worker_by_lua_block { lua-script } context: http phase: exiting-worker Runs the specified Lua code upon every Nginx worker process's exit when the master process is enabled.

exit_worker_by_lua_file #

syntax: exit_worker_by_lua_file 1 arg;  ·  context: http

This directive was first introduced in the v0.10.18 release. Back to TOC exit_worker_by_lua_file ----------------------- syntax: exit_worker_by_lua_file <path-to-lua-script-file> context: http phase: exiting-worker Similar to exit_worker_by_lua_block, but accepts the file path to a Lua source file or Lua bytecode file.

header_filter_by_lua #

syntax: header_filter_by_lua 1 arg;  ·  context: http, server, location, location-if

Nginx variables are supported in the file path for dynamic dispatch just as in content_by_lua_file. Back to TOC header_filter_by_lua -------------------- syntax: header_filter_by_lua <lua-script-str> context: http, server, location, location if phase: output-header-filter NOTE Use of this directive is discouraged following the v0.9.17 release.

header_filter_by_lua_block #

syntax: header_filter_by_lua_block no args;  ·  context: http, server, location, location-if

Use the header_filter_by_lua_block directive instead.

header_filter_by_lua_file #

syntax: header_filter_by_lua_file 1 arg;  ·  context: http, server, location, location-if

Processes outgoing response headers via Lua code loaded from a file, equivalent to header_filter_by_lua_block.

init_by_lua #

syntax: init_by_lua 1 arg;  ·  context: http

The cosockets are currently also disabled in the init_by_lua and init_worker_by_lua directive contexts but we may add support for these contexts in the future because there is no limitation in the Nginx core (or the limitation might be worked around).

init_by_lua_block #

syntax: init_by_lua_block no args;  ·  context: http

Use the init_by_lua_block directive instead.

init_by_lua_file #

syntax: init_by_lua_file 1 arg;  ·  context: http

Usually you can either use the init_by_lua or init_by_lua_file directives to load all such files or just make these Lua files true Lua modules and load them via require.

init_worker_by_lua #

syntax: init_worker_by_lua 1 arg;  ·  context: http

The cosockets are currently also disabled in the init_by_lua and init_worker_by_lua directive contexts but we may add support for these contexts in the future because there is no limitation in the Nginx core (or the limitation might be worked around).

init_worker_by_lua_block #

syntax: init_worker_by_lua_block no args;  ·  context: http

Use the init_worker_by_lua_block directive instead.

init_worker_by_lua_file #

syntax: init_worker_by_lua_file 1 arg;  ·  context: http

This hook no longer runs in the cache manager and cache loader processes since the v0.10.12 release. Back to TOC init_worker_by_lua_file ----------------------- syntax: init_worker_by_lua_file <lua-file-path> context: http phase: starting-worker Similar to init_worker_by_lua_block, but accepts the file path to a Lua source file or Lua bytecode file.

log_by_lua #

syntax: log_by_lua 1 arg;  ·  context: http, server, location, location-if

This directive was first introduced in the v0.5.0rc32 release. Back to TOC log_by_lua ---------- syntax: log_by_lua <lua-script-str> context: http, server, location, location if phase: log NOTE Use of this directive is discouraged following the v0.9.17 release.

log_by_lua_block #

syntax: log_by_lua_block no args;  ·  context: http, server, location, location-if

Use the log_by_lua_block directive instead.

log_by_lua_file #

syntax: log_by_lua_file 1 arg;  ·  context: http, server, location, location-if

Runs Lua code from a file during the log phase after a request completes, equivalent to log_by_lua_block.

lua_capture_error_log #

syntax: lua_capture_error_log 1 arg;  ·  context: http

Allocates a fixed-size buffer to capture all nginx error log messages in memory, retrievable later without reading log files.

lua_check_client_abort #

syntax: lua_check_client_abort on | off (on/off flag);  ·  context: http, server, location, location-if

This directive was first introduced in the v0.5.0rc32 release. Back to TOC lua_check_client_abort ---------------------- syntax: lua_check_client_abort on|off default: lua_check_client_abort off context: http, server, location, location-if This directive controls whether to check for premature client connection abortion.

lua_code_cache #

syntax: lua_code_cache on | off;  ·  context: http, server, location, location-if

This directive was first introduced in the v0.10.7 release. Back to TOC lua_code_cache -------------- syntax: lua_code_cache on | off default: lua_code_cache on context: http, server, location, location if Enables or disables the Lua code cache for Lua code in *_by_lua_file directives (like set_by_lua_file and content_by_lua_file) and Lua modules.

lua_fake_shm #

syntax: lua_fake_shm 2 args;  ·  context: http

Declares a fake shared-memory zone of the given size; a test-suite fixture directive, not for production use.

lua_http10_buffering #

syntax: lua_http10_buffering on | off (on/off flag);  ·  context: http, server, location, location-if

So when a HTTP 1.0 request is made and the lua_http10_buffering directive is turned on, ngx_lua will buffer the output of ngx.say and ngx.print calls and also postpone sending response headers until all the response body output is received.

lua_load_resty_core #

syntax: lua_load_resty_core on | off;  ·  context: http

Is deprecated and has no effect, since resty.core is always loaded automatically since v0.10.16.

lua_malloc_trim #

syntax: lua_malloc_trim 1 arg;  ·  context: http

Requests libc to release cached free memory back to the operating system every specified number of processed requests.

lua_max_pending_timers #

syntax: lua_max_pending_timers 1 arg (integer);  ·  context: http

Limits the maximum number of pending timers permitted at any time in a single nginx worker process.

lua_max_running_timers #

syntax: lua_max_running_timers 1 arg (integer);  ·  context: http

Limits the maximum number of concurrently running Lua timers permitted in a single nginx worker process.

lua_need_request_body #

syntax: lua_need_request_body on | off (on/off flag);  ·  context: http, server, location, location-if

This directive was first introduced in the v0.10.21 release. Back to TOC lua_need_request_body --------------------- syntax: lua_need_request_body <on|off> default: off context: http, server, location, location if phase: depends on usage Determines whether to force the request body data to be read before running rewrite/access/content_by_lua* or not.

lua_package_cpath #

syntax: lua_package_cpath 1 arg;  ·  context: http

Sets the Lua C module search path (cpath), supporting standard Lua cpath syntax and the special "$prefix" server-prefix notation.

lua_package_path #

syntax: lua_package_path 1 arg;  ·  context: http

This directive was first introduced in the v0.8.5 release. Back to TOC lua_package_path ---------------- syntax: lua_package_path <lua-style-path-str> default: The content of LUA_PATH environment variable or Lua's compiled-in defaults. context: http Sets the Lua module search path used by scripts specified by set_by_lua, content_by_lua and others.

lua_regex_cache_max_entries #

syntax: lua_regex_cache_max_entries 1 arg;  ·  context: http

Sets the maximum number of entries allowed in the worker-process-level compiled regular expression cache.

lua_regex_match_limit #

syntax: lua_regex_match_limit 1 arg;  ·  context: http

Sets the PCRE match limit controlling backtracking during ngx.re regex execution, using PCRE's default when set to zero.

lua_sa_restart #

syntax: lua_sa_restart on | off (on/off flag);  ·  context: http

Controls whether interrupted system calls automatically restart via the SA_RESTART signal flag.

lua_shared_dict #

syntax: lua_shared_dict 2 args;  ·  context: http

Declares a shared memory zone with the given name and size for storing data shared across all nginx worker processes.

lua_socket_buffer_size #

syntax: lua_socket_buffer_size 1 arg (size (k/m/g));  ·  context: http, server, location, location-if

This directive was first introduced in the v0.5.0rc1 release. Back to TOC lua_socket_buffer_size ---------------------- syntax: lua_socket_buffer_size <size> default: lua_socket_buffer_size 4k/8k context: http, server, location Specifies the buffer size used by cosocket reading operations.

lua_socket_connect_timeout #

syntax: lua_socket_connect_timeout 1 arg (duration in ms);  ·  context: http, server, location, location-if

Timeout for the connecting operation is controlled by the lua_socket_connect_timeout config directive and the settimeout method.

lua_socket_keepalive_timeout #

syntax: lua_socket_keepalive_timeout 1 arg (duration in ms);  ·  context: http, server, location, location-if

Note that this method does not affect the lua_socket_keepalive_timeout setting; the timeout argument to the setkeepalive method should be used for this purpose instead.

lua_socket_log_errors #

syntax: lua_socket_log_errors on | off (on/off flag);  ·  context: http, server, location, location-if

Controls whether cosocket TCP/UDP/Unix-domain-socket errors are logged to the nginx error log.

lua_socket_pool_size #

syntax: lua_socket_pool_size 1 arg (integer);  ·  context: http, server, location, location-if

If omitted but backlog was provided, the pool will be created with a default size equal to the value of the lua_socket_pool_size directive.

lua_socket_read_timeout #

syntax: lua_socket_read_timeout 1 arg (duration in ms);  ·  context: http, server, location, location-if

Timeout for the reading operation is controlled by the lua_socket_read_timeout config directive and the settimeout method.

lua_socket_send_lowat #

syntax: lua_socket_send_lowat 1 arg (size (k/m/g));  ·  context: http, server, location, location-if

Size in bytes; accepts k / m / g suffixes.

lua_socket_send_timeout #

syntax: lua_socket_send_timeout 1 arg (duration in ms);  ·  context: http, server, location, location-if

Timeout for the sending operation is controlled by the lua_socket_send_timeout config directive and the settimeout method.

lua_ssl_certificate #

syntax: lua_ssl_certificate 1 arg (list of strings);  ·  context: http, server, location

This directive was first introduced in the v0.9.11 release. Back to TOC lua_ssl_certificate ------------------- syntax: lua_ssl_certificate <file> default: none context: http, server, location Specifies the file path to the SSL/TLS certificate in PEM format used for the tcpsock:sslhandshake method.

lua_ssl_certificate_key #

syntax: lua_ssl_certificate_key 1 arg (list of strings);  ·  context: http, server, location

See also lua_ssl_certificate_key and lua_ssl_verify_depth. Back to TOC lua_ssl_certificate_key ----------------------- syntax: lua_ssl_certificate_key <file> default: none context: http, server, location Specifies the file path to the private key associated with the SSL/TLS certificate used in the tcpsock:sslhandshake method.

lua_ssl_ciphers #

syntax: lua_ssl_ciphers 1 arg (string);  ·  context: http, server, location

This directive was first introduced in the v0.5.13 release. Back to TOC lua_ssl_ciphers --------------- syntax: lua_ssl_ciphers <ciphers> default: lua_ssl_ciphers DEFAULT context: http, server, location Specifies the enabled ciphers for requests to a SSL/TLS server in the tcpsock:sslhandshake method.

lua_ssl_conf_command #

syntax: lua_ssl_conf_command 2 args (key value pair);  ·  context: http, server, location

Sets OpenSSL configuration commands applying to SSL/TLS connections initiated by cosockets.

lua_ssl_crl #

syntax: lua_ssl_crl 1 arg (string);  ·  context: http, server, location

This directive was first introduced in the v0.9.11 release. Back to TOC lua_ssl_crl ----------- syntax: lua_ssl_crl <file> default: no context: http, server, location Specifies a file with revoked certificates (CRL) in the PEM format used to verify the certificate of the SSL/TLS server in the tcpsock:sslhandshake method.

lua_ssl_key_log #

syntax: lua_ssl_key_log 1 arg (string);  ·  context: http, server, location

See also lua_ssl_certificate, lua_ssl_certificate_key and lua_ssl_trusted_certificate. Back to TOC lua_ssl_key_log --------------- syntax: lua_ssl_key_log <file> default: none context: http, server, location Enables logging of client connection SSL keys in the tcpsock:sslhandshake method and specifies the path to the key log file.

lua_ssl_protocols #

syntax: lua_ssl_protocols 1+ args (bitmask);  ·  context: http, server, location

Bitmask — combine several keywords.

lua_ssl_trusted_certificate #

syntax: lua_ssl_trusted_certificate 1 arg (string);  ·  context: http, server, location

See also lua_ssl_certificate, lua_ssl_certificate_key and lua_ssl_trusted_certificate. Back to TOC lua_ssl_key_log --------------- syntax: lua_ssl_key_log <file> default: none context: http, server, location Enables logging of client connection SSL keys in the tcpsock:sslhandshake method and specifies the path to the key log file.

lua_ssl_verify_depth #

syntax: lua_ssl_verify_depth 1 arg (integer);  ·  context: http, server, location

Sets the maximum verification depth for the peer certificate chain when cosockets perform SSL/TLS handshakes.

lua_thread_cache_max_entries #

syntax: lua_thread_cache_max_entries 1 arg (integer);  ·  context: http

Sets the maximum number of entries kept in the worker-process-level cache of reusable Lua thread (coroutine) objects.

lua_transform_underscores_in_response_headers #

syntax: lua_transform_underscores_in_response_headers on | off (on/off flag);  ·  context: http, server, location, location-if

Controls whether underscores in outgoing HTTP response header names get transformed into hyphens.

lua_upstream_skip_openssl_default_verify #

syntax: lua_upstream_skip_openssl_default_verify on | off (on/off flag);  ·  context: location, location-if

Boolean directive — set to "on" or "off".

lua_use_default_type #

syntax: lua_use_default_type on | off (on/off flag);  ·  context: http, server, location, location-if

Controls whether the default_type directive's MIME type is used as the default Content-Type response header value.

lua_worker_thread_vm_pool_size #

syntax: lua_worker_thread_vm_pool_size 1 arg (integer);  ·  context: http

This directive was first introduced in the v0.10.14 release. Back to TOC lua_worker_thread_vm_pool_size ------------------------------ syntax: lua_worker_thread_vm_pool_size <size> default: lua_worker_thread_vm_pool_size 10 context: http Specifies the size limit of the Lua VM pool (default 100) that will be used in the ngx.run_worker_thread API.

precontent_by_lua_block #

syntax: precontent_by_lua_block no args;  ·  context: http, server, location, location-if

This directive requires the ngx_devel_kit module. Back to TOC precontent_by_lua_block -------------------- syntax: precontent_by_lua_block { lua-script } context: http, server, location, location if phase: precontent tail Acts as a precontent phase handler and executes Lua code string specified in { <lua-script } for every request.

precontent_by_lua_file #

syntax: precontent_by_lua_file 1 arg;  ·  context: http, server, location, location-if

precontent_by_file filename;

precontent_by_lua_no_postpone #

syntax: precontent_by_lua_no_postpone on | off (on/off flag);  ·  context: http

Boolean directive — set to "on" or "off".

proxy_ssl_certificate_by_lua_block #

syntax: proxy_ssl_certificate_by_lua_block no args;  ·  context: location, location-if

Note also that, it has the same condition as the proxy_ssl_certificate directive for proxy_ssl_certificate_by_lua* to work, that is the upstream server should enable verification of client certificates.

proxy_ssl_certificate_by_lua_file #

syntax: proxy_ssl_certificate_by_lua_file 1 arg;  ·  context: location, location-if

Sets the client SSL certificate/key for upstream HTTPS connections via Lua code loaded from a file, equivalent to the _block variant.

proxy_ssl_verify_by_lua_block #

syntax: proxy_ssl_verify_by_lua_block no args;  ·  context: location, location-if

same context as proxy_pass directive

proxy_ssl_verify_by_lua_file #

syntax: proxy_ssl_verify_by_lua_file 1 arg;  ·  context: location, location-if

Verifies the upstream server's SSL certificate using Lua code loaded from a file, equivalent to proxy_ssl_verify_by_lua_block.

rewrite_by_lua #

syntax: rewrite_by_lua 1 arg;  ·  context: http, server, location, location-if

If the current location includes rewrite_by_lua directives, then the request body will be read just before the rewrite_by_lua code is run (and also at the rewrite phase).

rewrite_by_lua_block #

syntax: rewrite_by_lua_block no args;  ·  context: http, server, location, location-if

Use the rewrite_by_lua_block directive instead.

rewrite_by_lua_file #

syntax: rewrite_by_lua_file 1 arg;  ·  context: http, server, location, location-if

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.

rewrite_by_lua_no_postpone #

syntax: rewrite_by_lua_no_postpone on | off (on/off flag);  ·  context: http

The rewrite_by_lua_block code will always run at the end of the rewrite request-processing phase unless rewrite_by_lua_no_postpone is turned on.

server_rewrite_by_lua_block #

syntax: server_rewrite_by_lua_block no args;  ·  context: http, server

Just as any other rewrite phase handlers, server_rewrite_by_lua_block also runs in subrequests.

server_rewrite_by_lua_file #

syntax: server_rewrite_by_lua_file 1 arg;  ·  context: http, server

server_rewrite_by_lua_file filename;

set_by_lua #

syntax: set_by_lua 2+ args;  ·  context: server, location, server-if, location-if

This directive was first introduced in the v0.8.5 release. Back to TOC lua_package_path ---------------- syntax: lua_package_path &lt;lua-style-path-str&gt; default: The content of LUA_PATH environment variable or Lua's compiled-in defaults. context: http Sets the Lua module search path used by scripts specified by set_by_lua, content_by_lua and others.

set_by_lua_block #

syntax: set_by_lua_block 1 arg;  ·  context: server, location, server-if, location-if

Use the set_by_lua_block directive instead.

set_by_lua_file #

syntax: set_by_lua_file 2+ args;  ·  context: server, location, server-if, location-if

This directive was first introduced in the v0.10.7 release. Back to TOC lua_code_cache -------------- syntax: lua_code_cache on | off default: lua_code_cache on context: http, server, location, location if Enables or disables the Lua code cache for Lua code in *_by_lua_file directives (like set_by_lua_file and content_by_lua_file) and Lua modules.

ssl_certificate_by_lua_block #

syntax: ssl_certificate_by_lua_block no args;  ·  context: http, server

Runs inline Lua code just before nginx begins the SSL handshake for a downstream HTTPS connection, allowing dynamic certificate selection.

ssl_certificate_by_lua_file #

syntax: ssl_certificate_by_lua_file 1 arg;  ·  context: http, server

Runs Lua code or LuaJIT bytecode from the specified file just before nginx begins the SSL handshake for a downstream HTTPS connection.

ssl_client_hello_by_lua_block #

syntax: ssl_client_hello_by_lua_block no args;  ·  context: http, server

Runs Lua code upon receiving the downstream SSL ClientHello message, enabling dynamic SSL configuration based on SNI or other ClientHello data.

ssl_client_hello_by_lua_file #

syntax: ssl_client_hello_by_lua_file 1 arg;  ·  context: http, server

Equivalent to ssl_client_hello_by_lua_block but loads the Lua code from an external file.

ssl_session_fetch_by_lua_block #

syntax: ssl_session_fetch_by_lua_block no args;  ·  context: http

Runs Lua code to fetch SSL session data from external storage during SSL session resumption.

ssl_session_fetch_by_lua_file #

syntax: ssl_session_fetch_by_lua_file 1 arg;  ·  context: http

Equivalent to ssl_session_fetch_by_lua_block but loads the Lua code from an external file.

ssl_session_store_by_lua_block #

syntax: ssl_session_store_by_lua_block no args;  ·  context: http

This hook, together with the ssl_session_store_by_lua* hook, can be used to implement distributed caching mechanisms in pure Lua (based on the cosocket API, for example).

ssl_session_store_by_lua_file #

syntax: ssl_session_store_by_lua_file 1 arg;  ·  context: http

Stores SSL session data via Lua code loaded from an external file, equivalent to ssl_session_store_by_lua_block.

Example


 # set search paths for pure Lua external libraries (';;' is the default path):
 lua_package_path '/foo/bar/?.lua;/blah/?.lua;;';

 # set search paths for Lua external libraries written in C (can also use ';;'):
 lua_package_cpath '/bar/baz/?.so;/blah/blah/?.so;;';

 server {
     location /lua_content {
         # MIME type determined by default_type:
         default_type 'text/plain';

         content_by_lua_block {
             ngx.say('Hello,world!')
         }
     }

     location /nginx_var {
         # MIME type determined by default_type:
         default_type 'text/plain';

         # try access /nginx_var?a=hello,world
         content_by_lua_block {
             ngx.say(ngx.var.arg_a)
         }
     }

     location = /request_body {
         client_max_body_size 50k;
         client_body_buffer_size 50k;

         content_by_lua_block {
             ngx.req.read_body()  -- explicitly read the req body
             local data = ngx.req.get_body_data()
             if data then
                 ngx.say("body data:")
                 ngx.print(data)
                 return
             end

             -- body may get buffered in a temp file:
             local file = ngx.req.get_body_file()
             if file then
                 ngx.say("body is in file ", file)
             else
                 ngx.say("no body found")
             end
         }
     }

     # transparent non-blocking I/O in Lua via subrequests
     # (well, a better way is to use cosockets)
     location = /lua {
         # MIME type determined by default_type:
         default_type 'text/plain';

         content_by_lua_block {
             local res = ngx.location.capture("/some_other_location")
             if res then
                 ngx.say("status: ", res.status)
                 ngx.say("body:")
                 ngx.print(res.body)
             end
         }
     }

     location = /foo {
         rewrite_by_lua_block {
             res = ngx.location.capture("/memc",
                 { args = { cmd = "incr", key = ngx.var.uri } }
             )
         }

         proxy_pass http://blah.blah.com;
     }

     location = /mixed {
         rewrite_by_lua_file /path/to/rewrite.lua;
         access_by_lua_file /path/to/access.lua;
         content_by_lua_file /path/to/content.lua;
     }

     # use nginx var in code path
     # CAUTION: contents in nginx var m
…

↑ back to index