<!-- 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://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 и др.);
- реализация логики контроля доступа и безопасности до передачи запроса на
  backend;
- модификация заголовков ответа;
- извлечение информации о проксируемых серверах из внешних хранилищ и
  динамический выбор `upstream`;
- написание полноценных веб-приложений внутри `content handler`;
- маршрутизация URL на этапе rewrite;
- реализация расширенного кэширования для подзапросов и `location`.

Производительность LuaJIT-среды сопоставима с языком C: ее отличают высокая
скорость выполнения и низкое потребление памяти. Это делает Lua-интеграцию в
Angie особенно эффективной.

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

## Загрузка модуля

Использование требует предварительной загрузки модуля `ndk`. Загрузка
модулей в контексте `main{}`:

```nginx
load_module modules/ndk_http_module.so;
load_module modules/ngx_http_lua_module.so;    # для HTTP
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)
