Fail2Ban + CloudFlare
When protecting a server fail2ban is a great tool for the job. It reads log files and bans IPs that show signs of malicious activity. There is a lot of support for and it can integrate well with other applications.
How I Use it
I use CloudFlare on all my sites. This means that when you connect to any of my sites, you connect to cloudflare then CloudFlare connects to my site. Because of this, I have an rule in nginx (which I added a the bottom) that blocks any connections that attempt to connect directly to my server. I decided to increase the protection that I had on my server by creating a filter in fail2ban. I made it so connections are blocked for 5 minutes if the connection is made from an IP that is not from CloudFlare.
#Allow Cloudflare IPs #Retrived from https://www.cloudflare.com/ips/ allow 184.108.40.206/20; allow 220.127.116.11/22; allow 18.104.22.168/22; allow 22.214.171.124/22; allow 126.96.36.199/18; allow 188.8.131.52/18; allow 184.108.40.206/20; allow 220.127.116.11/20; allow 18.104.22.168/22; allow 22.214.171.124/17; allow 126.96.36.199/15; allow 188.8.131.52/12; allow 184.108.40.206/13; allow 220.127.116.11/22; allow 2400:cb00::/32; allow 2606:4700::/32; allow 2803:f800::/32; allow 2405:b500::/32; allow 2405:8100::/32; allow 2a06:98c0::/29; allow 2c0f:f248::/32; #Block all other IPs from connecting deny all;