Summary: Most server administrators instinctively reach for Nginx’s limit_req module to stop HTTP floods. Here is how an unexpected use case for UBAN (GitHub) lets you build a smarter, status-code-aware, kernel-level rate limiter, and why attempting this in Fail2ban turns a simple rule into a heavy, over-engineered setup.
I built UBAN, a lightweight, native C intrusion prevention daemon that tails server logs in real time and drops malicious IPs directly at the kernel level via nftables. It was built for high-speed pattern matching and instant blocking; it was never designed to do rate limiting.
Recently, though, I realized that rate limiting is actually an unexpectedly great use case for UBAN.

Why I Never Liked Nginx Rate Limiting
I have never liked Nginx’s built-in rate limiting (limit_req), and I don’t use it on my servers.
To configure it properly, you have to carve out shared memory zones in nginx.conf, guess at rate and burst buckets, and decide between delaying requests or rejecting them with HTTP 429/503 errors. Worse still, Nginx’s rate limiter has two major flaws when dealing with real-world scrapers and bots:
- It Treats Every Request Blindly: Nginx counts raw requests per second without caring what happened. A legitimate visitor loading 12 cached images on a heavy blog post looks identical to a scraper hammering 12 missing endpoints.
- It Has Short-Term Amnesia & Wastes CPU: Even when Nginx throttles a bot with a
503or429, Nginx still has to accept the TCP connection, evaluate the memory bucket, send back an HTTP response, and write to the error log. Once the bot slows down or pauses long enough for its excess-request counter to decay, it can resume sending requests without any persistent penalty. Nginx rate limiting regulates traffic; it doesn’t remember repeat offenders or escalate penalties.
That’s when it clicked: why manage rate limiting inside the web server at all when UBAN is already watching the access log in real time?
Measuring Real Human Traffic First (and Why max_retry = 16 Wasn’t Enough)
Before setting a rate limit, you need to know what normal human browsing actually looks like on your site.
My site is relatively lightweight. I opened a clean guest browser profile (cold cache) and clicked straight into the most image-heavy blog post on this entire domain. Looking at the Nginx access log, that single page load generated 13 HTTP 200 requests within one second, while browsing most other pages generated 10 or fewer requests per second. On repeat visits, local browser caching reduces those numbers even further.
Initially, I set max_retry = 16 within find_time = 1 and felt pretty happy with it—it gave legitimate readers on asset-heavy pages a safe buffer without false positives. After watching production logs for a bit, though, I realized that a ceiling of 16 requests per second isn’t actually very helpful against real scrapers. Because automated crawlers only fetch HTML documents and skip CSS, JS, and images, a scraper could grab 15 pages in a single second and still fly completely under the radar.
You can’t lower that number when every raw request is counted, because static files inflate a single human page load. So I added ignore_string and ignore_max_len (an added feature of UBAN v1.1.5) to filter out static assets and routine metadata requests before counting. Once CSS, JavaScript, media files, and favicons are ignored, a real human loading a page generates only 1 to 3 counted hits (such as an HTTP-to-HTTPS redirect, the HTML document, and an occasional browser prefetch)—letting me tighten max_retry all the way down to 5 requests per second with dramatically better results.
The UBAN Rate-Limiter Configuration
Assuming you have already placed $status at Position 2 in your Nginx log format (as covered in the UBAN Technical Deep Dive), setting up intelligent rate limiting takes just one jail block in /etc/uban/uban.conf followed by sudo systemctl reload uban:
enabled = true
log_path = "/var/log/nginx/access.log"
ip_pos = 1
match_pos = 2
match_string = "200", "204", "206", "301", "302", "304", "400", "401", "403", "404", "405", "408", "444", "499", "500", "502"
ignore_string = "GET /static/", "GET /media/", "GET /robots.txt", "GET /sitemap.xml", "GET /favicon.ico"
ignore_max_len = 128
max_retry = 5
find_time = 1
ban_time = 1
banfactor = 100
max_bantime = 28d
Four details make this configuration far sharper than standard web-server rate limiting:
- Status-Code Precision (
match_string): You decide which HTTP status codes count. Here, the jail tracks 16 high-signal codes across normal page loads (200,204,206), redirects and cache checks (301,302,304), selected client errors and scanner responses (including Nginx’s444and499), and upstream failures (500,502), while omitting noisy or internal codes like429or503. - Zero Asset Inflation (
ignore_string): By ignoring static assets (/static/,/media/,/favicon.ico) and standard crawler files (/robots.txt,/sitemap.xml), every counted hit represents an actual page request, redirect, or error response. That lets you safely dropmax_retryto5without catching real visitors on media-heavy posts. - Anti-Spoofing Guardrail (
ignore_max_len): Becauseignore_stringperforms fast substring matching on the log line, a clever attacker could try appending?GET /static/to a malicious URL or injecting it into a custom User-Agent string to bypass the rate limiter entirely. Settingignore_max_len = 128tells UBAN to only check the first 128 bytes of the log line—covering the IP, status code, timestamp, and request path—so anything hidden in query strings, referrers, or User-Agents is never exempted. - Human-Safe Tarpit Escalation (
ban_time = 1+banfactor = 100): A 1-second initial ban is practically invisible if a real user ever opens several tabs at once, yet it immediately severs an active bot’s connection pool innftables. If an automated scraper persists, the100xmultiplier escalates repeat strikes from1sto100s, then10,000s(~2.8 hours), and straight into the 28-day ceiling on the fourth strike.
Better yet, you don’t have to stop at a single time window. Because a human visitor exhibits a brief burst when loading a page and then goes quiet while reading, you can stack additional jails with identical settings but wider windows and lower per-second averages; for example, pairing a find_time = 1 / max_retry = 5 burst jail (5 req/s) with a find_time = 3 / max_retry = 8 jail (~2.7 req/s) and a find_time = 10 / max_retry = 15 jail (1.5 req/s). This multi-window envelope lets normal reading patterns pass untouched while catching throttled crawlers that pace themselves just under a 1-second ceiling.
Why This Beats Nginx (and Why Fail2ban Gets Heavy)
🛡️ Kernel Drop vs. HTTP 429
Once an IP crosses the threshold, UBAN blocks it at the kernel firewall level through nftables. Subsequent traffic is dropped before it reaches Nginx, eliminating HTTP request-processing and response-generation overhead for that offender.
📈 Escalating Bans
Unlike Nginx’s stateless buckets, UBAN tracks repeat offenders in SQLite and escalates their ban times automatically if they come back.
I came up with this idea completely independently and already had it deployed and tested on my production server before I ever searched to see if anyone else had tried it. Afterward, out of curiosity, I looked around online and found a great write-up on Schallbert’s Blog documenting a similar approach with Caddy and Fail2ban by filtering HTTP 200 responses. (Yes, sometimes I do like taking credit!) Interestingly, that author ran into the exact same static-asset inflation issue (two page clicks generating 35 log entries), ended up configuring Caddy’s log_skip /assets* to exclude asset hits from the logs, and wrestled with separate filter files, custom regexes, Unix timestamp date patterns, and Docker iptables chain overrides just to get a single rate-limit jail working.
That highlights the real trade-off when trying to turn Fail2ban into an access-log rate limiter: setup complexity and regex overhead. Because Fail2ban is designed around regex-based log filters, turning it into a general-purpose rate limiter means evaluating those filters against a continuous stream of ordinary access-log entries, including successful page views and asset requests. That introduces additional parsing and regex-processing overhead, along with considerably more configuration complexity.
UBAN, on the other hand, evaluates the status code at a fixed position using native C string matching and simple prefix-bounded substring exclusions, turning your log-banning daemon into a lightweight, kernel-level rate limiter with just a few lines of config.
Of course, every tool and defense layer has its limits. A request-rate jail like this will not catch bots that deliberately throttle themselves to one request every few seconds (legitimate search crawlers like Googlebot are naturally slow and well-behaved, whereas patient scrapers sometimes mimic that pace). Thankfully, rate limiting is just one piece of what UBAN does—it also gives you instant token-based jails for vulnerability probes, 404/444 scanners, bad User-Agents, and custom Nginx block reasons, all enforced in the kernel within milliseconds.
After deploying the jail, you should audit how it behaves against real traffic by running uban status nginx-ratelimit -d to inspect both active and historical bans. If any legitimate visitors get caught (for example, someone opening multiple tabs at once), compare the flagged timestamps in /var/log/uban/uban.log against /var/log/nginx/access.log, lift any false positive with sudo uban unban <IP>, and adjust your ignore_string, max_retry, or find_time thresholds accordingly. If you are looking for a faster, simpler way to protect your Linux servers without wrestling with bloated regex rules, check out UBAN on GitHub and explore the rest of the UBAN series.