Lua#

The Lua package integrates the Lua programming language into Angie’s event-driven processing model, allowing the server’s functionality to be extended with Lua scripts. It consists of two modules:

Installation#

To install the module, use one of the following packages:

  • Angie: angie-module-lua;

  • Angie PRO: angie-pro-module-lua.

Features#

Example use cases:

  • aggregating and processing output from various upstream servers (proxy, drizzle, postgres, redis, memcached, etc.);

  • implementing access control and security logic before passing the request to the backend;

  • modifying response headers;

  • retrieving upstream server data from external sources and dynamically selecting the upstream;

  • building complete web applications inside the content handler;

  • performing URL routing during the rewrite phase;

  • implementing advanced caching for subrequests and location blocks.

The LuaJIT environment offers performance comparable to C, with high execution speed and low memory usage. This makes Lua integration especially efficient in Angie.

Loading the Module#

Using the Lua module requires loading the ndk module beforehand. Modules are loaded in the main{} context as follows:

load_module modules/ndk_http_module.so;
load_module modules/ngx_http_lua_module.so;    # for HTTP
load_module modules/ngx_stream_lua_module.so;  # for Stream

Bundled Lua Libraries#

The following third-party libraries are installed along with the Lua modules:

  1. luajit2

  2. lua_chronos

  3. lua_cjson

  4. lua-dumper

  5. lua-ffi-zlib

  6. inspect.lua

  7. lua-resty-core

  8. lua-resty-hmac

  9. lua-resty-http

  10. lua-resty-jwt

  11. lua-resty-lrucache

  12. lua-resty-openidc

  13. lua-resty-openssl

  14. lua-resty-session

  15. lua-resty-string

Additional Information#

Comprehensive documentation and source code are available at: