Distributed Denial of Service (DDoS) attacks continue to escalate in both frequency and sophistication. The average attack size grew 28% year-over-year, with application-layer (Layer 7) attacks becoming the most common threat vector for self-hosted services. While cloud providers offer managed DDoS mitigation at a premium, a growing number of open-source tools let you build robust DDoS protection on your own infrastructure.
This guide compares four proven approaches to self-hosted DDoS protection: Nginx with rate-limiting modules, HAProxy with stick-table filtering, BunkerWeb as an integrated security reverse proxy, and CrowdSec for collaborative threat intelligence. Each solution is evaluated on detection capability, configuration complexity, resource overhead, and real-world effectiveness.
For related reading, see our BunkerWeb vs ModSecurity vs CrowdSec WAF comparison and the Fail2ban vs SSHGuard vs CrowdSec intrusion prevention guide. We also cover rate limiting and API throttling in a separate guide.
Why Self-Hosted DDoS Protection Matters
Relying solely on cloud-based DDoS protection introduces several risks: vendor lock-in, per-GB mitigation costs that scale unpredictably during attacks, and potential single points of failure when the protection provider itself is targeted. Self-hosted DDoS mitigation gives you:
- Full control over filtering rules, whitelisting, and response behavior
- Zero per-attack costs — open-source tools have no usage-based billing
- Privacy preservation — all traffic analysis stays on your infrastructure
- Immediate response — no waiting for provider ticket queues during an active attack
- Defense in depth — combine multiple layers (connection limiting, behavioral analysis, IP reputation) for comprehensive protection
The key insight is that most self-hosted services don’t need carrier-grade volumetric mitigation (which requires upstream ISP cooperation). What you do need is effective Layer 7 protection against HTTP floods, slowloris attacks, and application-specific abuse — and that’s exactly where these tools excel.
Understanding DDoS Attack Vectors
Before deploying any protection tool, it helps to understand what you’re defending against. DDoS attacks fall into three broad categories:
Volumetric Attacks (Layer 3/4)
These attacks saturate your network bandwidth with massive traffic volumes:
- UDP floods — random UDP packets to open or closed ports
- ICMP floods — ping-based bandwidth exhaustion
- DNS amplification — spoofed requests to open DNS resolvers generating responses 28-54x larger than the original query
- NTP amplification — similar to DNS but using NTP servers with monlist commands
Self-hosted tools alone cannot fully mitigate volumetric attacks that exceed your upstream bandwidth. You need upstream filtering from your ISP or a transit provider. However, you can reduce the impact through proper firewall rules and connection limiting.
Protocol Attacks (Layer 4)
These exploit weaknesses in network protocols to exhaust server resources:
- SYN floods — incomplete TCP handshakes consuming connection table entries
- Ping of Death — oversized ICMP packets causing buffer overflows
- Smurf attacks — ICMP echo requests to broadcast addresses
Tools like HAProxy and Nginx can mitigate these through connection rate limiting and SYN cookie support.
Application-Layer Attacks (Layer 7)
The most dangerous category for self-hosted services because they mimic legitimate traffic:
- HTTP floods — high-rate GET/POST requests to expensive endpoints (search, login, API)
- Slowloris — keeping connections open with partial HTTP requests
- Low-and-slow — distributed requests at rates just below detection thresholds
- WordPress XML-RPC abuse — using
xmlrpc.phpfor amplification - API endpoint abuse — hitting unauthenticated or expensive API routes
This is where self-hosted tools provide the most value. All four tools in this comparison excel at Layer 7 mitigation, each with different approaches.
Comparison at a Glance
| Feature | Nginx Rate Limiting | HAProxy Stick Tables | BunkerWeb | CrowdSec |
|---|---|---|---|---|
| Primary role | Reverse proxy + rate limiter | Load balancer + traffic filter | Security-first reverse proxy | Collaborative IPS |
| GitHub stars | N/A (core project) | 6,495 | 10,358 | 13,180 |
| Last updated | Continuously | 2026-04-25 | 2026-04-24 | 2026-04-24 |
| Language | C | C | Python | Go |
| Layer 7 protection | Yes (req/conn limiting) | Yes (stick-table ACLs) | Yes (built-in rules) | Yes (scenarios) |
| Layer 4 protection | Partial (conn limiting) | Yes (TCP rate limiting) | Yes (anti-DDoS module) | Partial (IP ban) |
| IP reputation | Manual (geoip/blocklist) | Manual (ACL lists) | Built-in bad bot DB | Crowdsourced (global) |
| Geo-blocking | Yes (geoip module) | Yes (ACL rules) | Yes (built-in) | Yes (scenarios) |
| Bot detection | Manual (user-agent ACLs) | Manual | Yes (built-in) | Yes (scenarios) |
| Docker support | Yes | Yes | Yes (native) | Yes (Docker parser) |
| Resource usage | Low (~50MB) | Low (~30MB) | Medium (~200MB) | Medium (~150MB) |
| Learning curve | Low | Medium | Low | Medium |
| Collaborative intel | No | No | No | Yes (global network) |
Nginx: Connection and Rate Limiting
Nginx provides two powerful built-in modules for DDoS mitigation without any third-party dependencies: ngx_http_limit_req_module for request rate limiting and ngx_http_limit_conn_module for connection limiting.
Basic Rate Limiting Configuration
| |
Advanced: Custom Error Responses and Logging
| |
Docker Compose for Nginx DDoS Protection
| |
HAProxy: Stick-Table Traffic Filtering
HAProxy’s stick-table feature provides granular traffic tracking and filtering based on request rates, connection counts, and HTTP error rates. Unlike Nginx’s static rate limits, HAProxy can dynamically track and respond to suspicious behavior patterns.
Stick-Table Configuration
| |
Geo-Blocking with HAProxy
| |
HAProxy Docker Compose
| |
BunkerWeb: Integrated Security Reverse Proxy
BunkerWeb (10,358 stars, last updated 2026-04-24) is a purpose-built security reverse proxy based on Nginx. It comes with DDoS protection features pre-configured, making it the most turnkey solution in this comparison.
Key Anti-DDoS Features
- Anti-bot detection — JavaScript challenge, CAPTCHA, and behavioral analysis
- Request rate limiting — configurable per-IP and per-URL limits
- Connection limiting — max concurrent connections per IP
- Bad user-agent blocking — blocks known scanner and bot user-agents
- Geo-blocking — country-level IP filtering with built-in GeoIP
- DNSBL integration — checks IPs against DNS-based blackhole lists
- Auto-ban — automatically bans IPs that trigger security rules
BunkerWeb Docker Compose
| |
BunkerWeb Environment Variables for DDoS
| Variable | Default | Description |
|---|---|---|
LIMIT_REQ_RATE | 10r/s | Max requests per second per IP |
LIMIT_REQ_BURST | 20 | Burst allowance before blocking |
LIMIT_CONN | 10 | Max concurrent connections per IP |
BLOCK_ABUSE_IP | yes | Auto-ban IPs triggering rules |
USE_BAD_BEHAVIOR | yes | Enable behavioral bot detection |
USE_DNSBL | no | Check IPs against DNS blocklists |
BLOCK_COUNTRY | Empty | Comma-separated country codes to block |
USE_ANTISCAN | yes | Block known vulnerability scanners |
CrowdSec: Collaborative Threat Intelligence
CrowdSec (13,180 stars, last updated 2026-04-24) takes a fundamentally different approach: instead of relying solely on local rules, it shares threat intelligence across a global network of 90,000+ nodes. When one node detects and bans an attacking IP, all other nodes can benefit from that intelligence.
How CrowdSec Works
- Bouncer agents — installed alongside your services (Nginx bouncer, HAProxy bouncer, Traefik bouncer, firewall bouncer)
- Local agent — analyzes logs in real-time using YAML-based “scenarios”
- CTI (CrowdSec Threat Intelligence) — queries the central API for IP reputation data
- Community blocklist — contributes detected bad IPs and receives bans from the global network
Installing CrowdSec with Docker
| |
DDoS-Specific Scenarios
CrowdSec includes pre-built scenarios that detect DDoS patterns:
| |
The http-ddos scenario triggers when an IP sends more than 100 requests within 10 seconds, resulting in a temporary ban. Combined with CrowdSec’s community blocklist, you automatically benefit from bans enacted by other nodes worldwide.
Firewall Bouncer for Network-Level Blocking
For maximum DDoS protection, use the firewall bouncer to block at the OS level before traffic reaches your application:
| |
Layered DDoS Defense Strategy
The most effective self-hosted DDoS protection combines multiple tools in a defense-in-depth architecture:
| |
Recommended Deployment for Most Users
For a typical self-hosted setup, this combination provides comprehensive protection with manageable complexity:
- Front layer: HAProxy for connection routing and basic rate limiting
- Security layer: BunkerWeb for anti-bot detection and behavioral analysis
- Intelligence layer: CrowdSec for collaborative IP reputation and automated banning
- Application layer: Nginx as the final request filter before your app
Minimal Setup (Low Resource)
If resources are limited, a single CrowdSec instance with the Nginx bouncer provides 80% of the protection of a full stack:
| |
Choosing the Right Tool
| Scenario | Recommended Tool | Why |
|---|---|---|
| Simple rate limiting | Nginx | Built-in, zero dependencies, battle-tested |
| Complex traffic filtering | HAProxy | Stick-tables provide unmatched flexibility |
| Turnkey security proxy | BunkerWeb | Pre-configured rules, web UI for management |
| Collaborative protection | CrowdSec | Global threat intelligence network |
| WordPress site | BunkerWeb + CrowdSec | Anti-bot + CVE detection scenarios |
| API service | Nginx + HAProxy | Fine-grained per-endpoint rate limits |
| Multi-server setup | CrowdSec | Shared blocklist across all nodes |
| Minimal resources | Nginx rate limiting | ~50MB memory, handles thousands of req/s |
Troubleshooting Common Issues
Legitimate Users Getting Blocked
If legitimate users are hitting rate limits, adjust the burst parameters and consider whitelisting known IP ranges:
| |
False Positives from Search Engine Crawlers
Search engine bots can trigger rate limits. Exclude them by user-agent:
| |
High Memory Usage with Large Stick Tables
If HAProxy’s stick table consumes too much memory, reduce the table size or expire entries faster:
| |
FAQ
What is the difference between DDoS and DoS attacks?
A DoS (Denial of Service) attack comes from a single source, while a DDoS (Distributed Denial of Service) attack originates from multiple sources simultaneously, often a botnet of compromised devices. DDoS attacks are harder to block because the traffic comes from many different IPs, making simple IP banning less effective.
Can self-hosted tools stop volumetric DDoS attacks?
No. Volumetric attacks that exceed your upstream bandwidth (e.g., 100 Gbps) cannot be stopped by any self-hosted tool because the traffic saturates your network link before reaching your server. For volumetric mitigation, you need upstream filtering from your ISP or a DDoS protection service like Cloudflare or Akamai. Self-hosted tools excel at Layer 7 (application-layer) attacks, which is the most common threat for self-hosted services.
How does CrowdSec’s community blocklist work?
When any CrowdSec node detects and bans a malicious IP, that ban decision is shared to the central CrowdSec API. Other nodes can query this API to check if an IP has been flagged by the community. CrowdSec’s threat intelligence score combines frequency, recency, and severity of reports across the network. In practice, this means you benefit from bans enacted by 90,000+ other nodes worldwide.
Should I use Nginx or HAProxy for DDoS protection?
Use Nginx if you need simple, effective rate limiting with minimal configuration. Use HAProxy if you need more sophisticated traffic analysis (per-endpoint rate limits, error-rate tracking, tarpitting) or if HAProxy is already your load balancer. Both are excellent choices — many production setups use both, with HAProxy at the front and Nginx behind it.
Is BunkerWeb production-ready for high-traffic sites?
Yes. BunkerWeb is built on Nginx and has been tested with thousands of requests per second. The security features add approximately 10-15% CPU overhead compared to vanilla Nginx. For sites receiving more than 10,000 requests/second, consider using HAProxy or Nginx with custom rate limiting instead, as BunkerWeb’s feature set may introduce latency at extreme scale.
How do I test if my DDoS protection is working?
Use tools like slowloris (for slowloris testing) and hping3 (for SYN flood testing) from a separate machine to simulate attacks:
| |
Monitor your logs during testing to verify that rate limiting and IP banning are triggered correctly. Always test from a non-production environment to avoid accidentally getting yourself banned.