if I want to block any IPs that connects the server more than 5 times per second, how to do that?

I am currently using CloudFlare firewall to manually block such IPs but it would be nice to make it automatically in Apache2 server.

I know there is a .htaccess but not sure if this can be set to block such IPs.


The first step will be to restore the correct user IP in your log files so they show your user's IP Address instead of CloudFlare.

In order to do this you can install Mod_CloudFlare.

After you've done this; you can then install Fail2Ban. Fail2Ban can then be configured to Rate Limit requests from IP Addresses of your choice.

Fail2Ban will then watch your Apache log file, once it spots excessive requests; those IPs will be banned using a firewall tool (e.g. IPTables). The Digital Ocean community has a great tutorial on protecting Apache with Fail2Ban.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.