Security10 min read
WAF Protection
Protect your apps and compose stacks at the nginx edge with rate limiting, IP blocking, security headers, and ModSecurity + OWASP CRS in prevention (block) mode.
1.Enable WAF per App or Server
Team defaults apply when no per-resource policy exists; per-resource overrides win.
- Go to Security → WAF in dashboard
- Configure Team Defaults: toggle Enabled, set Rate limit (e.g., 20 r/s burst 40), HSTS max-age, CSP
- Click New Policy → choose Resource type:
app,composeorserver - Select resource by name (e.g., my-app, my-stack, This-VPS)
- Toggle Enabled → Mode is locked to
prevention(blocks with 403/429 at nginx) - Save — policy is stored and applied on next deploy / nginx reload (no downtime,
nginx -tvalidated)
2.Configure Rate Limiting & Security Headers
Lightweight WAF (available on Pro): nginx-native, no extra install.
- Set Rate limit r/s and Burst — creates global
limit_req_zone $binary_remote_addr zone=waf:10m rate=20r/sin/etc/nginx/conf.d/waf-zone.conf - Exceeding limit returns
429(limit_req_status 429) - Set Client max body size (e.g.,
10m) — injected asclient_max_body_size - Headers auto-injected:
X-Frame-Options: SAMEORIGIN,X-Content-Type-Options: nosniff,Referrer-Policy: strict-origin-when-cross-origin - Optional CSP (e.g.,
default-src 'self') and HSTS (max-age=31536000; includeSubDomains) — added viaadd_header ... always - Bypass:
location /.well-known/acme-challenge/always hasmodsecurity off; limit_req off;so Let's Encrypt never blocked
3.OWASP CRS & ModSecurity (Enterprise)
Full OWASP Top-10 coverage via ModSecurity v3 + OWASP Core Rule Set.
- Requires Enterprise plan (
waf_advanced) — gate checked viabilling.CheckFeature - On server, run WAF → Setup Server or SSH:
apt-get update && apt-get install -y libnginx-mod-security2 modsecurity-crs && nginx -t && systemctl reload nginx - In policy, enable ModSecurity + OWASP CRS toggle
- Choose Paranoia 1-4 (1 = default, higher = stricter, more false positives)
- When enabled, vhost gets
modsecurity on; modsecurity_rules_file /etc/nginx/modsec/main.conf; - Logs to
/var/log/nginx/waf.loganderror.log— tail viaGET /api/waf/events?server_id=...
4.Custom Rules & IP Blocks
Combine managed OWASP presets with your own allow/block logic (prevention).
- In WAF policy, add Custom Rules: target
path|query|ua|header|method|ip, actionblock(orallow), pattern (regex for path/query/ua, CIDR for ip) - Examples: block
/admin→if ($request_uri ~ "/admin") { return 403; }; block UAsqlmap; block headerX-Custom: bad - Allow rules are rendered first (nginx
allowbeforedeny) - Use IP Blocks tab:
Block IP / CIDR(e.g.,1.2.3.4or1.2.3.0/24) — rendered asdeny 1.2.3.4;in vhost - Set optional
expires_at(RFC3339) for temporary blocks - Test:
POST /api/waf/policies/{id}/testdry-runsnginx -t; delete policy to fall back to team defaults