<!-- review: finished -->

<a id="external-lua"></a>

# 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:

- `lua-nginx-module` — [https://github.com/openresty/lua-nginx-module](https://github.com/openresty/lua-nginx-module)
- `stream-lua-nginx-module` —
  [https://github.com/openresty/stream-lua-nginx-module](https://github.com/openresty/stream-lua-nginx-module)

<a id="installation-16"></a>

## Installation

To [install](https://en.angie.software//angie/docs/installation/index.md#install-packages) the module, use one of the following packages:

- Angie: `angie-module-lua`;
- Angie PRO: `angie-pro-module-lua`.

<a id="features"></a>

## 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.

<a id="loading-the-module-16"></a>

## Loading the Module

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

```nginx
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
```

<a id="bundled-lua-libraries"></a>

## Bundled Lua Libraries

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

1. [luajit2](https://github.com/openresty/luajit2)
2. [lua_chronos](https://github.com/ldrumm/chronos)
3. [lua_cjson](https://github.com/mpx/lua-cjson)
4. [lua-dumper](https://github.com/edubart/lua-dumper)
5. [lua-ffi-zlib](https://github.com/hamishforbes/lua-ffi-zlib)
6. [inspect.lua](https://github.com/kikito/inspect.lua)
7. [lua-resty-core](https://github.com/openresty/lua-resty-core)
8. [lua-resty-hmac](https://github.com/jkeys089/lua-resty-hmac)
9. [lua-resty-http](https://github.com/ledgetech/lua-resty-http)
10. [lua-resty-jwt](https://github.com/cdbattags/lua-resty-jwt)
11. [lua-resty-lrucache](https://github.com/openresty/lua-resty-lrucache)
12. [lua-resty-openidc](https://github.com/zmartzone/lua-resty-openidc)
13. [lua-resty-openssl](https://github.com/fffonion/lua-resty-openssl)
14. [lua-resty-session](https://github.com/bungle/lua-resty-session)
15. [lua-resty-string](https://github.com/openresty/lua-resty-string)

<a id="additional-information-17"></a>

## Additional Information

Comprehensive documentation and source code are available at:

- [https://github.com/openresty/lua-nginx-module](https://github.com/openresty/lua-nginx-module)
- [https://github.com/openresty/stream-lua-nginx-module](https://github.com/openresty/stream-lua-nginx-module)
