How To Install mod_evasive on Apache 2.4 in Rocky Linux 9

If you’re running Apache 2.4 on Rocky Linux 9 and want to protect your web server against basic DoS, DDoS, or brute-force attacks, installing mod_evasive
is a solid option. Unfortunately, the module isn’t included by default, and some manual work is required to get it running. Here’s a quick guide to getting it installed and patched for Apache 2.4.
Step-by-Step Installation
Note: All commands are run as the root user. You may also use sudo
in front of each command.
Configure mod_evasive
to your needs. You’ll typically add a configuration block like this to your Apache config:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
vi /etc/httpd/conf.d/mod_evasive.conf <IfModule mod_evasive20.c> DOSHashTableSize 3097 DOSPageCount 20 DOSSiteCount 100 DOSPageInterval 1 DOSSiteInterval 1 DOSBlockingPeriod 60 DOSEmailNotify you@example.com DOSSystemCommand "sudo -u apache /usr/bin/logger -p local7.notice mod_evasive triggered" DOSLogDir "/var/log/httpd/mod_evasive" </IfModule> |
Create the log directory and ensure Apache has permission to write to it:
1 2 3 |
mkdir -p /var/log/httpd/mod_evasive chmod 700 /var/log/httpd/mod_evasive chown apache:apache /var/log/httpd/mod_evasive |
Download and unpack the source:
1 2 3 |
wget https://github.com/jzdziarski/mod_evasive/archive/refs/heads/master.zip unzip master.zip cd mod_evasive-master |
For Apache 2.4, the source code needs a small patch to compile cleanly. Let’s handle that next:
1 2 3 |
dnf install -y patch wget https://wyzaerd.com/public/mod_evasive20.c.patch patch -b mod_evasive20.c < mod_evasive20.c.patch |
Once patched, you can build and install the module using apxs
:
1 |
apxs -i -a -c mod_evasive20.c |
This compiles the module, installs it into Apache’s modules directory, and updates your configuration to load it automatically.
Restart the Apache web server:
1 |
systemctl restart httpd |
Reference
More information, including source updates and configuration details, is available on the official GitHub repository: https://github.com/jzdziarski/mod_evasive
Leave Your Comment
All fields marked with "*" are required.