DEV Community

Tech Gard pro
Tech Gard pro

Posted on

Protecting Nginx Web Server with Fail2ban on Ubuntu 24.04 LTS

Protecting Nginx Web Server with Fail2ban on Ubuntu 24.04 LTS 🛡️
Securing a web server is a fundamental step after deploying any production application. If you are hosting an Nginx web server on Ubuntu 24.04 LTS, it is constantly probed by malicious bots, brute-force login attempts, and vulnerability scanners.
While a traditional firewall like UFW blocks static ports, Fail2ban provides dynamic defense. It scans Nginx log files in real-time and automatically uses UFW rules to ban IP addresses exhibiting malicious behavior.
Quick Configuration Summary

  1. Install Fail2ban Update package index and install Fail2ban:sudo apt update && sudo apt install fail2ban -y
  2. Create Local Jail Config Always create a .local copy to avoid losing configurations during updates:sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
  3. Configure Nginx Jails In /etc/fail2ban/jail.local, enable botsearch and HTTP auth protection:[nginx-botsearch] enabled = true port = http,https logpath = %(nginx_error_log)s maxretry = 2 findtime = 10m bantime = 24h
  4. Restart & Verify sudo systemctl restart fail2ban sudo fail2ban-client status 📖 Full Step-by-Step Tutorial This is a quick overview. For the complete guide—including custom HTTP auth jail setup, unbanning IPs, and integrating Fail2ban with UFW—check out the full tutorial on my blog: 👉 Read the Full Guide:https://mobilestuff2026.blogspot.com/2026/10/how-to-configure-fail2ban-to-protect.html

Top comments (0)