Bot protection on Apache HTTP Server
A mod_lua access checker validates requests before your content handler or mod_proxy runs, leaving virtual hosts and backend routing untouched.
How it fits into Apache
- Execution phase
- LuaHookAccessChecker runs centinel-handler.lua early in the access phase, before your content handler or mod_proxy.
- Requirements
- Apache 2.4+ with mod_lua and the Lua 5.1 libraries lua-curl, lua-socket and lua-cjson.
- Timeouts and failure mode
- 500 ms request and 300 ms connect timeouts. The module always fails open; there is no fail-closed mode.
- Route scoping
- Every non-static path by default. protected_paths takes Lua patterns such as ^/api/ in a custom handler.
How a request moves through Apache
With LuaScope server, one Lua state per server keeps an HTTP/2 connection to the validator open between requests.
Access checker
Apache calls access_check() in centinel-handler.lua. Images, fonts, stylesheets, scripts, media, archives, .json and .xml skip validation.
Validator call
lcurl sends the request over the reused HTTP/2 connection with CENTINEL_SECRET_KEY, which reaches Lua through PassEnv.
Decision
Allow hands control back to Apache and your handler runs. Block or challenge serves the validator's page, with at most one Set-Cookie header.
Failure
A slow, unreachable or failing validator lets the request through. A missing lcurl library also turns validation off without an error.
Minimal configuration and a live check
Hook the module into httpd.conf
LoadModule lua_module modules/mod_lua.so
# Add your distro's Lua 5.1 package paths here too
LuaPackagePath /usr/local/lib/lua/?.lua
PassEnv CENTINEL_SECRET_KEY
PassEnv CENTINEL_VALIDATOR_URL
PassEnv CENTINEL_DEBUG
# Persist Lua state across requests (required for connection reuse)
LuaScope server
LuaHookAccessChecker /usr/local/lib/lua/centinel-handler.lua access_check earlyWithout LuaScope server, Apache creates a fresh Lua state per request and pays for a new TLS handshake on every validation.
Send a scripted request
curl -s -o /dev/null -w '%{http_code}\n' -A 'python-requests/2.31' http://localhost/api/testExpect 403 once blocking is enabled, or 200 with a logged event in your Centinel dashboard while running in log-only mode. A 200 with no dashboard activity and no [Centinel] lines in the Apache error log usually means the module failed to load or lcurl is missing.
Deployment options
Packages on Alpine, Debian or Ubuntu
Extract centinel-apache.zip into /usr/local/lib/lua/, install the Lua 5.1 libraries, add the directives to httpd.conf and set CENTINEL_SECRET_KEY in the systemd unit.
Apache install guide (opens in a new tab)Docker on Alpine
Build from alpine:3.21 with apache2-lua and the lua5.1 packages, copy the directives into conf.d/centinel.conf and pass CENTINEL_SECRET_KEY with docker run -e.
Apache Docker setup (opens in a new tab)
What to know before deploying
Install lcurl from luarocks on Debian and Ubuntu
The lua-curl apt package installs without lcurl.so, so require("lcurl") fails. Run luarocks install Lua-cURLv3 LUA_VERSION=5.1 CURL_INCDIR=/usr/include.
Build against Lua 5.1
luarocks uses Lua 5.3 or 5.4 headers by default, but mod_lua uses 5.1. A mismatched build fails with undefined symbol: lua_tointeger.
Missing mime module turns challenges into allows
Without the mime module from lua-socket, base64 challenge decoding fails silently so interstitial challenges pass through as allow while blocks serve a generic page.
The shipped handler reads three variables
centinel-handler.lua reads only CENTINEL_SECRET_KEY, CENTINEL_VALIDATOR_URL and CENTINEL_DEBUG. For protected_paths or timeouts, write your own handler and point LuaHookAccessChecker at it.
Add exclusions without losing the static list
Setting unprotected_paths in centinel.init() replaces the static-asset list. centinel.add_unprotected_pattern("^/health$") after init() keeps it.
What stays untouched
- Your virtual hosts, TLS termination and authentication modules
- Your mod_proxy backends and application code
- Static files that match the default exclusions
- Your existing .htaccess rewrite rules
Apache integration questions
Walk through your Apache setup
Bring one route bots are hitting. We will map the right connector, timeouts, and log-only rollout for your Apache stack.