nginx-waf-lua

April 1, 2026 ยท View on GitHub

OpenResty/Lua integration library for nginx-waf.

Overview

nginx-waf-lua provides a Lua library for OpenResty that reads nginx-waf IP list files, provides fast IP lookups, custom block responses, and runtime list management.

Features

  • Read nginx-waf IP list files
  • Fast IP matching (IPv4/IPv6 + CIDR)
  • Shared dict caching for performance
  • Custom block response handling
  • Runtime block/unblock with TTL
  • Drop-in access phase handler

Quick Start

-- In OpenResty nginx.conf
lua_shared_dict waf_cache 10m;

init_by_lua_block {
    local waf = require("resty.waf")
    waf.init({
        lists_dir = "/etc/nginx/waf-lists",
        shared_dict = "waf_cache",
    })
}

access_by_lua_block {
    local waf = require("resty.waf")
    waf.check_request()
}

API

local waf = require("resty.waf")

waf.init(opts)                  -- Initialize with options
waf.is_blocked(ip)              -- Check if IP is blocked
waf.is_allowed(ip)              -- Check if IP is allowed
waf.check_request()             -- Full access phase handler
waf.block(ip, opts)             -- Block IP at runtime
waf.unblock(ip)                 -- Unblock IP

Installation

From OBS packages

Available for Fedora, openSUSE, Debian, and Ubuntu via OBS.

From source

make install PREFIX=/usr/local/openresty

From LuaRocks (future)

luarocks install nginx-waf-lua

nginx-waf Ecosystem

Other Nginx Modules

License

BSD 3-Clause License - see LICENSE.md for details.