<!-- review: finished -->

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

# Lua

Lua 软件包将 Lua 编程语言集成到 Angie 的事件驱动处理模型中,允许使用 Lua 脚本扩展服务器的功能。
它由两个模块组成:

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

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

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

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

## 功能特性

示例用例:

- 聚合和处理来自各种 `upstream` 服务器的输出
  (proxy、drizzle、postgres、redis、memcached 等);
- 在将请求传递给后端之前实现访问控制和安全逻辑;
- 修改响应头;
- 从外部源检索上游服务器数据并动态选择 `upstream`;
- 在 `content handler` 内构建完整的 Web 应用程序;
- 在重写阶段执行 URL 路由;
- 为子请求和 `location` 块实现高级缓存。

LuaJIT 环境提供与 C 语言相当的性能,具有高执行速度和低内存使用率。这使得 Lua 集成在 Angie 中特别高效。

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

## 加载模块

使用 Lua 模块需要预先加载 `ndk` 模块。
模块在 `main{}` 上下文中加载,如下所示:

```nginx
load_module modules/ndk_http_module.so;
load_module modules/ngx_http_lua_module.so;    # 用于 HTTP
load_module modules/ngx_stream_lua_module.so;  # 用于 Stream
```

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

## 捆绑的 Lua 库

以下第三方库与 Lua 模块一起安装:

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>

## 其他信息

完整的文档和源代码可在以下位置获取:

- [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)
