Latest version supported: https://nginx.org/download/nginx-1.27.4.tar.gz
- News
- Screenshots
- Test Cases
- Introduction
- Features
- Prerequisites
- Recommended SSL Configuration
- Recommended Lua Extensions
- Install
- Install (Docker)
- Now you can try it without installing anything. Pre-built docker image released.
Kubernetes support added for
- Horizontal Pod Autoscaler (HPA) for automatic scaling
- Scalability
- Dynamic Configuration
- Rolling updates
1. minikube start --driver=docker
2. cd docker
>> Windows / Powershell
minikube docker-env | Invoke-Expression
3. docker build `
--build-arg VER_NGINX=1.27.4 `
--build-arg VER_LUAROCKS=3.11.1 `
--build-arg VER_LUA=5.1 `
-t v2-nginx-lua .
>> MacOS/Linux
eval $(minikube docker-env)
docker build \
--build-arg VER_NGINX=1.27.4 \
--build-arg VER_LUAROCKS=3.11.1 \
--build-arg VER_LUA=5.1 \
-t v2-nginx-lua .
4. kubectl apply -f nginx-deployment.yaml
# Check pods
kubectl get pods
# Check services
kubectl get svc
# Check logs
kubectl logs <pod-name>
# Get the URL for the deployment
minikube service nginx-service --url
PS C:\Users\Katana\lua-nginx-modsec-bot-blocker> kubectl logs v2-nginx-lua-666c7798f4-bx4r4
2025/03/17 14:55:54 [notice] 1#1: ModSecurity-nginx v1.0.3 (rules loaded inline/local/remote: 0/798/0)
2025/03/17 14:55:54 [notice] 1#1: libmodsecurity3 version 3.0.14
2025/03/17 14:55:54 [notice] 1#1: using the "epoll" event method
2025/03/17 14:55:54 [notice] 1#1: nginx/1.27.4
2025/03/17 14:55:54 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
2025/03/17 14:55:54 [notice] 1#1: OS: Linux 5.15.167.4-microsoft-standard-WSL2
2025/03/17 14:55:54 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2025/03/17 14:55:54 [notice] 1#1: start worker processes
2025/03/17 14:55:54 [notice] 1#1: start worker process 7
2025/03/17 14:55:54 [notice] 1#1: start worker process 8
2025/03/17 14:55:54 [notice] 1#1: start worker process 9
2025/03/17 14:55:54 [notice] 1#1: start worker process 10
2025/03/17 14:55:54 [notice] 1#1: start worker process 11
2025/03/17 14:55:54 [notice] 1#1: start worker process 12
2025/03/17 14:55:54 [notice] 1#1: start worker process 13
2025/03/17 14:55:54 [notice] 1#1: start worker process 14
2025/03/17 14:55:54 [notice] 1#1: start worker process 15
2025/03/17 14:55:54 [notice] 1#1: start worker process 16
2025/03/17 14:55:54 [notice] 1#1: start worker process 17
2025/03/17 14:55:54 [notice] 1#1: start worker process 18
2025/03/17 14:55:54 [notice] 1#1: start worker process 19
2025/03/17 14:55:54 [notice] 1#1: start worker process 20
2025/03/17 14:55:54 [notice] 1#1: start worker process 21
2025/03/17 14:55:54 [notice] 1#1: start worker process 22
10.244.0.1 - - [17/Mar/2025:14:56:00 +0000] "GET /healthz HTTP/1.1" 200 2 "-" "kube-probe/1.32"
10.244.0.1 - - [17/Mar/2025:14:56:03 +0000] "GET /healthz HTTP/1.1" 200 2 "-" "kube-probe/1.32"
10.244.0.1 - - [17/Mar/2025:14:56:05 +0000] "GET /healthz HTTP/1.1" 200 2 "-" "kube-probe/1.32"
PS C:\Users\Katana\lua-nginx-modsec-bot-blocker>
docker run --rm -d --name test-nginx -p 5002:80 derank123/lua-ubuntu-nginx-modsec-bot-blocker:1.27.4
- Change port if 5002 is unavailable for you, as it is set to 5002 for host
- For port 80 ->
docker run -d -p 80:80
-
Possibility to build for custom nginx version
-
Test-cases included
-
Optional modules you can install (it will be updated in the future):
- nginx-ultimate-bad-bot-blocker
Code:
location /admin {
content_by_lua_block {
local auth = ngx.var.http_authorization
local expected_auth = "Basic " .. ngx.encode_base64("admin:password")
if not auth or auth ~= expected_auth then
ngx.header["WWW-Authenticate"] = 'Basic realm="Restricted Area"'
ngx.exit(ngx.HTTP_UNAUTHORIZED)
end
ngx.say("Access granted!")
}
}
curl -v http://localhost/admin
Expected: 401
curl -v -H "Authorization: Basic $(echo -n 'admin:password' | base64)" http://localhost/admin
Expected: 200 OK with "Access granted!"
Code:
location /lua_security_test {
content_by_lua_block {
local bad_patterns = {
"script", -- Blocks HTML script tags
"SELECT", -- Blocks SQL SELECT statements
"UNION" -- Blocks SQL UNION operators
}
local query = ngx.var.query_string or ""
for _, pattern in ipairs(bad_patterns) do
if string.find(query, pattern, 1, true) then
ngx.exit(ngx.HTTP_FORBIDDEN)
end
end
ngx.say("Query is safe!")
}
}
curl -v "http://localhost/lua_security_test?q=safe_query"
Expected: 200 OK
curl -v "http://localhost/lua_security_test?input=<script>alert(1)</script>"
Expected: 403 Forbidden
Code:
location /say_hello_lua {
content_by_lua_block {
ngx.say("Hello from lua-nginx-module!")
ngx.header["Content-Type"] = "text/plain"
ngx.header["X-Lua-Powered"] = "true"
}
}
curl -v http://localhost/say_hello_lua
curl -v "http://localhost/?id=1%27%20OR%201=1--"
Expected: 403 Forbidden (ModSecurity blocking SQLi)
curl -v "http://localhost/?param=<script>alert('XSS')</script>"
Expected: 403 Forbidden
curl -A "Xenu Link Sleuth" -I http://localhost
Expected: Empty reply from server
A hardened Nginx build with integrated security features including Lua scripting, ModSecurity WAF, OWASP Core Rule Set, and advanced bot protection.
- Nginx 1.27.4 with custom-compiled modules
- LuaJIT 2.1 scripting support
- ModSecurity 3.0 Web Application Firewall
- OWASP Core Rule Set protection
- Nginx Ultimate Bad Bot Blocker
- GeoIP2 support
- Lua RESTy components:
- lua-resty-core
- lua-resty-lrucache
- lua-resty-redis
- lua-resty-mysql
- And more...
- Stream and HTTP Lua modules
- Enhanced security headers
- Thread support and modern protocol support
- Ubuntu 24.04 (or compatible Debian-based system)
- Root/sudo access
- 2GB+ RAM (4GB recommended for compilation)
- 5GB+ disk space
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
ssl_ecdh_curve secp384r1;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
sudo luarocks install lua-resty-jwt
sudo luarocks install lua-resty-http
location /lua-test {
content_by_lua_block {
ngx.say("Hello from Lua!")
ngx.log(ngx.ERR, "Custom Lua logging")
}
}
- Clone the repo
- Make sh executable
- Run it with sudo
Note. Ubuntu 24.04 (or compatible Debian-based system)
Docker image based on Debian
What you can customize:
- NGINX version
- LUAROCKS version
- LUA
docker build `
--build-arg VER_NGINX=1.27.4 `
--build-arg VER_LUAROCKS=3.11.1 `
--build-arg VER_LUA=5.1 `
-t v2-nginx-lua .
docker build \
--build-arg VER_NGINX=1.27.4 \
--build-arg VER_LUAROCKS=3.11.1 \
--build-arg VER_LUA=5.1 \
-t v2-nginx-lua .
docker run --rm -it -p 5002:80 docker.io/library/v2-nginx-lua:latest