Here’s what your snippet does—it’s a Fail2Ban “jail” configuration for Nginx, enabling two separate protections:
1. [nginx-http-auth]
ini
[nginx-http-auth]
enabled = true
Purpose
Watches for repeated HTTP authentication failures (e.g. bad user/password on a “Basic Auth”–protected location) and bans the offending IP.
enabled = true
Turns this jail on. Without additional options, it uses default settings from your main jail.conf (like the filter name nginx-http-auth, default log path, bantime, etc.).
This jail specifically looks for “bot‐like” patterns in your access.log (scanning, vulnerability probing, etc.) and actively bans IPs that exceed a threshold.
Directive
Meaning
enabled = true
Activate this jail.
port = http,https
Apply the ban to both port 80 and 443.
filter = nginx-botsearch
Use the regex rules in /etc/fail2ban/filter.d/nginx-botsearch.conf.
logpath = /var/log/nginx/access.log
File to scan for matching bot‐traffic patterns.
maxretry = 5
Number of “bad requests” allowed before banning.
findtime = 600
Time window (in seconds) during which the 5 bad requests count.
bantime = 600
How long (in seconds) the IP remains banned (10 minutes).
How it works, step by step
Fail2Ban tails /var/log/nginx/access.log.
Any entry matching the nginx-botsearch regex (e.g. scanning for /wp-login.php, SQLi probes, common bot user-agents) is counted.
If an IP hits ≥ 5 matches within 600 s, Fail2Ban adds a temporary iptables rule blocking that IP on HTTP/HTTPS ports.
After 600 s, the ban is lifted automatically—if the IP misbehaves again, it can be re-banned.
nginx-botsearch: Thwarts automated scanners, crawlers and known bad bots probing your site.
Feel free to tweak maxretry, findtime and bantime to suit your threat model—longer bans for persistent attackers, or shorter for more lenient policies. 👍
User
do you think 5 and 600 are good value for those parameters ? should I add jail to my fail2ban nginx ?
Assistant
Tuning “maxretry” and “findtime” is always a balance between blocking bad actors quickly and avoiding false-positives on legitimate clients. Here’s how to decide if 5 retries in 600 s (10 minutes) makes sense for you:
Typical Defaults
• maxretry = 5
• findtime = 600
• bantime = 600 (10 min)
These are conservative, widely used defaults. They’ll catch most automated scanners without unduly punishing normal users who occasionally hit a missing resource.
When to Tighten (more security)
• Lower maxretry to 3 or 4—bans kick in faster.
• Shorten findtime to 300 s (5 min) if you want quicker reaction.
• Increase bantime (e.g. 3600 s or even 86400 s) to punish persistent scanners longer.
When to Relax (fewer false-positives)
• Raise maxretry to 8–10 if your site legitimately produces a handful of 404s or odd‐URL requests (think big APIs or many microservices).
• Keep bantime low (300–600 s) so any accidental bans heal quickly.
Should you add this jail?
Absolutely—if you run a public‐facing Nginx server you’ll want some form of bot-search protection. Here’s how to do it cleanly:
Create or edit /etc/fail2ban/jail.d/nginx-botsearch.local
ini
[nginx-botsearch]
enabled = true
port = http,https
filter = nginx-botsearch
logpath = /var/log/nginx/access.log
maxretry = 5 ; adjust up/down as needed
findtime = 600 ; e.g. 300 for faster bans
bantime = 600 ; e.g. 3600 for longer blocks
action = iptables-multiport[name=nginx-botsearch, port="http,https", protocol=tcp]
Reload Fail2Ban
bash
sudo fail2ban-client reload
Verify it’s running
bash
sudo fail2ban-client status nginx-botsearch
Quick checklist
• Watch your logs for false-positives under /var/log/fail2ban.log.
• If legit clients get banned, tweak maxretry↑ or findtime↓.
• If you still see scans slipping through, tighten maxretry↓ or increase bantime.
In short: start with 5/600/600, monitor for a week, then adjust up or down based on your traffic and tolerance for risk. 🚀
User
do you have other nail that i should use to protect my nginx server ? and what is the page that is pushed on the screen of someone that is banned ?
Assistant
Here are a few more “jails” and hardening tricks you can layer on top of nginx-botsearch/nginx-http-auth, plus notes on what a banned client actually sees.
1. Additional Fail2Ban jails for Nginx
nginx-404
• Watches for excessive 404s, a common sign of URL brute-forcing or scanner noise.
• Example config (/etc/fail2ban/filter.d/nginx-404.conf ships with many distros):
http-get-dos
• Generic “slow-loris” or flood detection: too many GETs in too short a time.
• You can find plenty of examples online—just adjust maxretry/findtime for your traffic.
recidive
• Watches the main fail2ban.log for repeat offenders and slaps on a long-term ban (e.g. 24 h).
By default Fail2Ban uses iptables to or the TCP connection. This means:
DROP
REJECT
• If it’s a DROP rule → the client’s browser will hang until it times out (no HTTP status, no nginx “error page”).
• If configured to REJECT → immediately gets “Connection refused” (TCP RST).
There is no “nginx serves a fancy HTML page” out of the box. If you do want a custom block page:
Change your action from DROP to REJECT (so the TCP handshake fails fast), or better…
Use a custom action that adds a deny 1.2.3.4; to an include file in your nginx vhost, then nginx -s reload.
• Denied clients get your normal error_page 403 /blocked.html; experience.
• Example action snippet in /etc/fail2ban/action.d/nginx-block.conf:
• Yes, add more jails like nginx-404, http-get-dos and a recidive jail for longer-term offenders.
• Layer on Nginx’s native limit_req/limit_conn, a WAF (ModSecurity/NAXSI), and strict TLS/cookie headers.
• By default banned IPs see nothing (connection drops). If you want a “You’re banned” splash page, swap your Fail2Ban action to update Nginx’s deny list and use a 403 error_page.