The best NGINX security modules are ModSecurity with the OWASP Core Rule Set for a full web application firewall, NAXSI for a lightweight strict WAF, Coraza for a modern ModSecurity-compatible engine, headers-more for response headers, the built-in limit_req and limit_conn modules for rate limiting, auth_request and JWT for authentication, and GeoIP2 for location-based blocking. Start in detection mode, tune the rules, then enforce.
Key takeaways
- ModSecurity with the OWASP Core Rule Set is the standard NGINX WAF, but it needs tuning to avoid blocking legitimate traffic.
- Built-in modules already cover rate limiting, access control and security headers — add third-party modules only for what they cannot do.
- Always start a WAF in detection or learning mode, log everything, and block nothing until false positives are fixed.
NGINX already sits in front of a huge share of the web, which makes it a good place to stop attacks before they reach your application. The built-in modules cover rate limiting, access control and headers — and a handful of third-party modules add a full web application firewall, modern authentication and bot controls.
How did we choose these NGINX security modules?
We chose modules that are actively maintained, documented, and widely used in production, and that solve a security problem the built-in modules cannot solve alone. Every pick below is open source and free to use, except where noted as a commercial NGINX Plus feature.
Our criteria were: maintenance status in 2026, quality of documentation, breadth of attack coverage, tuning burden, and how well the module fits a small team without a dedicated WAF engineer. We did not test performance claims, and we did not rank by benchmarks — a WAF you cannot tune is worse than no WAF at all.
One warning applies to every module here: install it in detection or learning mode first. A WAF switched straight to blocking mode will block legitimate users, and you will learn about it from angry customers, not from your logs.
What are the best NGINX security modules at a glance?
This table compares the eight modules on what they do, what they cost, and who should pick them. Detail follows below.
| Module | Best for | Cost | Key feature |
|---|---|---|---|
| ModSecurity + OWASP CRS | Full WAF on varied apps | Free, open source | OWASP Top 10 rules, virtual patching |
| NAXSI | Strict WAF, few apps | Free, open source | Learning mode, low rule maintenance |
| OWASP Coraza | Modern, containerized stacks | Free, open source | ModSecurity-compatible rules, Go engine |
| headers-more | Fine-grained header control | Free, open source | Set, clear and rewrite any header |
| limit_req / limit_conn | Brute force and floods | Free, built in | Per-IP rate and connection limits |
| auth_request + JWT | Authentication at the edge | Free / Plus for JWT | Delegate auth to a service or token |
| GeoIP2 | Location-based blocking | Free module, paid database | Block or allow by country |
| ngx_http_access + secure_link | Simple access control | Free, built in | IP allow lists, expiring signed URLs |
The WAF layer: stop attacks before they reach your app
A web application firewall inspects requests and blocks known attack patterns — SQL injection, cross-site scripting, path traversal and protocol abuse — before your application ever sees them. These three modules are the main choices for NGINX.
1. ModSecurity with OWASP CRS — best full WAF
ModSecurity is the open source WAF engine most people mean when they say open source WAF. Paired with the OWASP Core Rule Set (CRS), it inspects requests against maintained rules covering injection, cross-site scripting and the OWASP Top 10, and supports virtual patching — blocking an exploit for a vulnerability you have not yet patched.
- Key features: SecLang rules, OWASP CRS, audit logging, detection-only mode, virtual patching.
- Pros: deepest rule knowledge, huge community, works with CRS 4, well documented.
- Cons: needs tuning and false-positive handling; NGINX support is via the v3 connector, and CRS does not support NGINX with ModSecurity v2.
- Pricing: free and open source under the Apache License 2.0. No license cost; the cost is your time tuning it.
- Who should pick it: teams with varied applications who want the standard, best-documented WAF for NGINX.
ModSecurity moved to OWASP stewardship in January 2024, after Trustwave transferred the project, as documented on the OWASP ModSecurity project page. As of November 2026 the current releases are v2.9.15 and v3.0.17, and the OWASP CRS is at 4.30.0, with 4.25.x as the long-term support line. Start with SecRuleEngine DetectionOnly, log everything, and only switch to blocking after false positives are fixed.
2. NAXSI — best strict, low-maintenance WAF
NAXSI (NGINX Anti XSS and SQL Injection) is a high-performance, low-maintenance WAF module for NGINX. Instead of loading thousands of signatures, it looks for dangerous characters and expressions — for example, <, | and drop are generally not supposed to be part of a URI — and scores each request against a small set of simple rules.
- Key features: learning mode, whitelist generation, SQL injection and cross-site scripting scoring, low overhead.
- Pros: small rule set, fast, little ongoing rule maintenance once whitelists are built.
- Cons: upfront work in learning mode; whitelists are per application and must be reviewed carefully.
- Pricing: free and open source.
- Who should pick it: NGINX teams with a handful of well-understood applications who can invest a week in learning mode.
3. OWASP Coraza — best modern WAF for containers and Kubernetes
Coraza is an OWASP project that runs ModSecurity-compatible rules, including the OWASP CRS, in a Go engine. That makes it a natural fit for Kubernetes, ingress controllers and proxy-heavy stacks, where a Go-native WAF is easier to deploy than a C module.
- Key features: ModSecurity-compatible rules, OWASP CRS support, connectors for NGINX, Envoy, Traefik and Caddy, Go engine.
- Pros: modern codebase, container-friendly, reuses CRS knowledge.
- Cons: newer than ModSecurity, so fewer decade-old forum threads when something breaks.
- Pricing: free and open source under the Apache License 2.0.
- Who should pick it: teams running NGINX in containers or behind a modern ingress, who want CRS coverage without the ModSecurity v3 connector.
Headers, rate limiting and access control
The next group needs no WAF at all. These modules — most of them built into NGINX — close the gaps attackers probe first: missing headers, unlimited login attempts, and open admin routes.
4. headers-more — best for fine-grained header control
The built-in add_header directive covers most sites, but it cannot remove or rewrite headers set by your application or by NGINX itself. The headers-more module can set, add and clear arbitrary request and response headers, per status code, which is why it is a staple of OpenResty-based stacks.
- Key features: set, clear and rewrite headers, per-status filtering, request and response headers.
- Pros: precise control, including removing version headers that leak information.
- Cons: third-party module, so you need to build NGINX with it or use a package that includes it.
- Pricing: free and open source.
- Who should pick it: teams that need to strip leaking headers or set different headers per route and status code.
If you only need standard security headers — HSTS, Content-Security-Policy, X-Frame-Options, X-Content-Type-Options — the built-in directive is enough. Always add the always parameter so headers appear on error responses too, and verify the result with our free security headers checker.
5. limit_req and limit_conn — best built-in rate limiting
These two built-in modules are the first defense against brute force and application-layer floods. limit_req limits how fast a client can make requests, and limit_conn limits how many connections one client can hold open at once. Together they make password guessing slow and expensive, and they blunt simple floods.
- Key features: per-IP zones, burst tolerance, custom 429 responses, separate zones per endpoint.
- Pros: built into NGINX, no extra module, well documented, low overhead.
- Cons: per-IP limits are weaker behind shared NAT and against distributed attacks.
- Pricing: free, included with NGINX Open Source.
- Who should pick it: everyone. Set a strict zone for login and admin routes, and a looser one for the rest of the site.
A typical pattern is a zone of 5 requests per minute for login, 10 to 20 per second for an API, and a burst allowance so a legitimate user is not blocked by one fast page load. Log rejected requests, and watch for a single IP hammering login — that is a brute-force attempt, not a busy user.
6. auth_request and JWT — best authentication at the edge
auth_request is a built-in module that delegates authorization to a subrequest: NGINX asks your authentication service whether this request may proceed, and the service answers with 2xx to allow or 401 or 403 to refuse. It fits when authentication is already handled by another service, such as OAuth2 Proxy.
- Key features: subrequest auth, header forwarding, works with any auth service behind an HTTP endpoint.
- Pros: keeps auth logic out of NGINX config, works with existing identity providers.
- Cons: adds a subrequest per protected request, so keep the auth service fast and local.
- Pricing: auth_request is free and built in. JWT validation with
auth_jwtis an NGINX Plus feature, sold on request. - Who should pick it: teams with an existing auth service or API gateway who want NGINX to enforce it at the edge.
For simple cases, auth_basic — also built in — protects an admin route with a hashed password file, provided it runs over HTTPS. It is enough for a staging site or an internal tool, but not a substitute for real authentication on a public application.
7. GeoIP2 — best for location-based blocking
GeoIP2 creates variables from the client IP address using MaxMind GeoIP2 databases, so you can allow or block by country, or route traffic differently by region. It is useful when your legitimate users are in a handful of countries and the attack traffic is not.
- Key features: country, city and ASN lookup, variables for use in maps and access rules.
- Pros: simple to configure, effective against geographically concentrated abuse.
- Cons: the module is free but the database is a separate MaxMind product; country blocking can lock out legitimate travellers and VPN users.
- Pricing: module free and open source; MaxMind GeoIP2 databases have free and paid tiers — check MaxMind's current pricing before budgeting.
- Who should pick it: sites with a clear geographic audience who see sustained abuse from specific countries.
8. ngx_http_access and secure_link — best simple access control
These two built-in modules handle the simplest cases well. ngx_http_access allows or denies by IP address or network, which is enough to restrict an admin panel to your office IP or a VPN range. secure_link checks the authenticity of a requested link, protects resources from unauthorized access, and limits link lifetime — useful for expiring download links.
- Key features: IP allow and deny lists, signed expiring URLs, per-location rules.
- Pros: built in, zero extra dependencies, easy to audit.
- Cons: IP lists do not scale to many users, and IPs change.
- Pricing: free, included with NGINX Open Source.
- Who should pick it: anyone restricting an admin route to a known IP range, or issuing time-limited download links.
Remember the /.well-known/ exception: if you block hidden files with a /\. location, add an explicit allow for /.well-known/, or ACME certificate renewal through HTTP-01 will fail and your site will lose its certificate.
How do I choose the right NGINX security modules?
Map your traffic path first, then pick the smallest set that covers it. A single WordPress site behind NGINX needs headers, rate limiting on login, and a WAF in detection mode. A Kubernetes ingress needs Coraza or ModSecurity at the ingress, plus rate limits and auth delegation. An API needs JWT or auth_request, strict rate limits per key, and request-size limits.
Do not stack two WAFs. ModSecurity plus NAXSI plus Coraza will fight each other, double your false positives, and make it impossible to tell which rule blocked a request. Pick one WAF, tune it, and spend the saved effort on patching and backups.
What should I avoid when hardening NGINX?
The most common mistakes are not missing modules but misconfiguration. Never expose the NGINX version in error pages — set server_tokens off. Never allow unneeded HTTP methods on an application that only needs GET and POST. Never leave autoindex on, and never serve hidden files.
Keep client body and header sizes bounded with client_max_body_size and client_header_buffer_size, so a single huge request cannot exhaust memory. Test every config change with nginx -t before reloading, and keep the previous working config so you can roll back in seconds.
Finally, do not treat NGINX as your only defense. A WAF cannot fix an unpatched application, a weak password, or an exposed database. Use it as one layer — alongside updates, backups and authentication — and check the whole site with our free SSL checker after any change.
For a wider baseline, our small business cybersecurity checklist covers the controls that sit behind the reverse proxy. The official NGINX directive index is the reference for every built-in module named here.
The bottom line
For most NGINX sites, the right stack is small: built-in rate limiting and access control, solid security headers, and one WAF — ModSecurity with the OWASP CRS for varied apps, NAXSI for a few strict ones, or Coraza for containers.
Install in detection mode, tune until legitimate traffic passes cleanly, then enforce. A WAF you have tuned is a real defense; a WAF you switched on and forgot is a source of outages and false confidence.
Frequently asked questions
What is the best NGINX security module?
For most sites, ModSecurity with the OWASP Core Rule Set is the best NGINX WAF because it covers SQL injection, cross-site scripting and the OWASP Top 10 with maintained rules. NAXSI is better for small, well-understood apps that want a strict, low-maintenance WAF.
Is ModSecurity still maintained?
Yes. Trustwave transferred ModSecurity to OWASP in January 2024, and OWASP now maintains it. The current releases are v2.9.15 and v3.0.17, both published in September 2026.
Do I need a WAF if I use NGINX?
A WAF helps, but it is not a substitute for patching, strong authentication and secure code. NGINX built-in modules already block many attacks through rate limiting, access control and headers. Add a WAF when you need inspection of request bodies and known attack patterns.
What is the difference between ModSecurity and NAXSI?
ModSecurity uses a large set of signatures from the OWASP Core Rule Set and is highly configurable. NAXSI uses a small set of simple scoring rules based on dangerous characters, starts strict, and relies on whitelists built in learning mode. ModSecurity suits varied apps; NAXSI suits a few well-understood apps.
Can NGINX block bots and DDoS attacks?
NGINX can slow and block many abusive clients with limit_req and limit_conn, connection limits, and GeoIP-based blocking. Those controls help against brute force and application-layer floods, but a large volumetric DDoS still needs upstream protection from your host or a CDN.
How do I add security headers in NGINX?
Use the built-in add_header directive, or the third-party headers-more module for finer control, including removing headers. Always use the always parameter so headers also appear on error responses.
Is NGINX Plus worth it for security?
NGINX Plus adds commercial features including JWT authentication and a live activity monitoring dashboard, plus support. For many small teams, open source NGINX with ModSecurity, rate limiting and headers covers the same ground at no license cost. Pricing for NGINX Plus is not published; it is sold on request.
How do I test a new NGINX security module safely?
Start in detection or learning mode, log everything, and block nothing. Review the logs for a week or two, fix false positives with exclusions or whitelists, and only then switch to blocking mode.
Sources
The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.
Checked against NGINX official documentation, OWASP ModSecurity and Core Rule Set documentation, and the Coraza and NAXSI project repositories.
How we write and fact-check →