Block specific IP addresses during the Nginx access phase using a Lua script instead of static config rules
Generate API responses dynamically from Lua code without running a separate backend application server
Read and inspect incoming request bodies inside Nginx before deciding whether to forward them upstream
Build a high-performance rate limiter or auth check that runs inside Nginx's event loop using coroutines
Must be compiled into Nginx at build time or installed via the OpenResty distribution, dropping it into a standard Nginx binary is not possible.
lua-nginx-module is a plugin for the Nginx web server that lets you write request-handling logic in Lua, a lightweight scripting language. Instead of configuring Nginx purely through its static config file, you can write small Lua scripts that run at different points in the request lifecycle, such as when a request first arrives, when Nginx checks whether access is allowed, or when it is time to generate the response. The module is a core part of OpenResty, which is a distribution of Nginx bundled with this module and a collection of Lua libraries for building web applications and API servers. The README notes that using this module is essentially the same as using OpenResty. It embeds LuaJIT, a fast implementation of Lua, directly into Nginx's worker processes. The standard Lua interpreter is no longer supported as of version 0.10.16. The configuration examples in the README show how Lua code can be placed inline in the Nginx config file inside blocks like content_by_lua_block or rewrite_by_lua_block. You can also point Nginx to a separate .lua file instead of writing the code inline. From inside a Lua script, you have access to the incoming request, the request body, Nginx variables, and the ability to make internal sub-requests to other locations defined in the Nginx config. Typical uses described in the README include checking client IP addresses against a blocklist during the access phase, reading and inspecting request bodies, and generating response content dynamically without a separate application server. Because it runs inside Nginx's event loop, Lua code that does network calls uses coroutines rather than blocking threads, which keeps the server responsive under high load. The module is described as production ready. Community support is available through English and Chinese mailing lists. The full README is longer than what was shown.
← openresty on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.