Spammers are everywhere.
Even though it's a cat and mouse game it feels so good when we can block them :)

This tutorial assumes that you have root access to the server.
This example is tested on Ubuntu but should work for any apache installation.

Steps
Create a file called /etc/apache2/conf-available/00_block_ips.conf with the following contents.

[code]
ErrorDocument 403 "The content is not available. If you think this is an error contact us via domain.com"

# Global ip blocklist
<Directory "/var/www/">
deny from 1.2.3.4 # some explanation
</Directory>
[/code]

Enable the cofig file.

[code]
a2enconf 00_block_ips
[/code]

We file starts with 00 so it's one of the first conf files to be loaded.

You should see something like this.

[code]
Enabling conf 00_block_ips.
To activate the new configuration, you need to run:
service apache2 reload
[/code]

Reload apache conf

[code]
service apache2 reload
[/code]

Feel free to customize the text in the quotes after ErrorDocument 403 so people who were accidentally blocked can do something about it.

If you want to temporarily disable the ip block do this

[code]
a2disconf 00_block_ips
service apache2 reload
[/code]

Referral Note: When you purchase through an referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer