Fail2Ban + Nginx (WordPress-friendly): 5 suspicious requests → 5-minute ban (iptables-nft fix, testing and IP unban)

This guide shows a complete Fail2Ban installation and configuration for Nginx and WordPress, designed to:

  • block scanners and bots (e.g. attempts to access /.env, /.git, phpmyadmin, etc.),
  • avoid blocking the WordPress administrator,
  • ban IP addresses after 5 suspicious or invalid requests,
  • apply only a 5-minute ban (no risk of locking yourself out for long).

Step 1: Install Fail2Ban

Install Fail2Ban:

Enable and start the service:

Verify that it is running:

Step 2: Create the nginx-secure filter

Create the filter file:

Paste the following configuration:

Step 3: Create the nginx-secure jail

Create the jail configuration file:

Paste the following configuration:

Step 4: Restart Fail2Ban

Step 5: Verify firewall integration

Check that the Fail2Ban chain exists:

External test

Run from another machine:

After 5 attempts, the IP address will be banned for 5 minutes.

Check banned IPs

Unban IP address

Unban your IP manually:

Summary

  • protects against scanners and exploit attempts,
  • does not block the WordPress admin panel,
  • uses a short 5-minute ban duration,
  • fully compatible with iptables-nft,
  • easy to test and easy to unban IP addresses.