Skip to content

Instantly share code, notes, and snippets.

@benfavre
Last active April 12, 2024 16:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benfavre/2f2662e5df01476763d93520ddff2972 to your computer and use it in GitHub Desktop.
Save benfavre/2f2662e5df01476763d93520ddff2972 to your computer and use it in GitHub Desktop.
fail2ban WordPress Nginx

Restart service

sudo service fail2ban restart

Look at logs

tail -f /var/log/fail2ban.log

Manually add IP to jail

fail2ban-client set nginx-wp-login banip 185.39.10.73

Show jailed

sudo fail2ban-client status nginx-wp-login
# /etc/fail2ban/filter.d/nginx-wp-login.conf
[Definition]
failregex = ^<HOST> .* "POST /wp-login.php
^<HOST> .* "POST /wp/wp-login.php
^<HOST> .* "POST .*xmlrpc.php
ignoreregex =
# /etc/fail2ban/jail.d/nginx-wp-login.conf
[nginx-wp-login]
enabled = true
port = http,https
filter = nginx-wp-login
action = iptables-multiport[name=nginx-wp-login, port="http,https", protocol=tcp]
logpath = /var/log/nginx/access.log
/var/www/some_site/access_log
maxretry = 8
findtime = 600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment