How to use Zenfirewall with apache

The steps to add ZenFirewall IPs to your Apache configuration are as follows:

  1. Download the blocklist file and generate a configuration file suitable for Apache. This command can be added to a cron job and executed once or twice per day:

    curl -sf https://zenfirewall.com/zenblock.txt | sed 's/$/ BLOCKED/' > /etc/apache2/blocked_ips.txt

  2. In each virtual host where you want to apply this list:

    <VirtualHost *:80>
        ServerName test.com
    
        RewriteEngine On
        RewriteMap blocked_ips txt:/etc/apache2/blocked_ips.txt
        RewriteCond ${blocked_ips:%{REMOTE_ADDR}|NOT_BLOCKED} !=NOT_BLOCKED
        RewriteRule ^ - [F]
    
        # ...
    
    </VirtualHost>