How to install mod_evasive on cPanel Servers
mod_evasive is an Apache module by Jonathan Zdziarski to provide evasive action in the event of an HTTP DoS or DDoS attack or brute force attack. It is also designed to be a detection and network management tool, and can be easily configured to talk to ipchains, firewalls, routers, and etcetera. mod_evasive presently reports abuses via email and syslog facilities.
This article is using version 1.10.1 (stable). You can grab the latest from Zdziarski.
- Login to your server as the root user via SSH terminal.
- Let’s navigate to the default ‘source’ directory and download the latest module for Apache to compile against.
cd /usr/local/src/ curl -Ls https://go.khtechs.com/modevasive > /usr/local/src/mod_evasive.tar.gz
- Extract the newly downloaded archive and move into it’s directory.
tar xf mod_evasive.tar.gz cd /usr/local/src/mod_evasive
- Perform the following command to build the module from it’s source:
/usr/local/apache/bin/apxs -i -a -c mod_evasive24.c
- Once completed successfully, you should see a few lines of output, ending with:
[activating module `evasive20' in /usr/local/apache/conf/httpd.conf]
- We also need to tell Apache where to look for mod_evasive’s configurations. Open Apache’s configuration file and look for ‘LoadModule evasive*’, right below it add:
- That created an entry in the Apache configuration, however cPanel’s EasyApache will remove it on any rebuild/upgrade unless we distill it.
- You’ll receive ‘Distilled successfully’ as long as all syntax is correct.
- Now that we know it won’t be removed from the main configuration, we can add our mod_evasive.conf.
touch /usr/local/apache/conf/includes/mod_evasive.conf nano mod_evasive.conf
- When nano opens, add the following (or your custom configuration) to the file:
<IfModule mod_evasive20.c> DOSHashTableSize 3097 DOSPageCount 2 DOSSiteCount 50 DOSPageInterval 1 DOSSiteInterval 1 DOSBlockingPeriod 3600 DOSLogDir "/var/log/mod_evasive" DOSWhitelist 127.0.0.1 </IfModule>
- Let’s make the directory for logs.
- Test the configuration syntax to make sure everything is correct.
/usr/local/apache/bin/apachectl configtest Syntax OK
- Restart Apache.
- Check to make sure the evasive module is running.
/usr/local/apache/bin/apachectl -M | grep evasive
- To ensure EasyApache rebuilds mod_evasive with upgrades of Apache, rebuilds, etc. perform the following:
echo "/usr/local/apache/bin/apxs -i -a -c /usr/local/src/mod_evasive/mod_evasive24.c" >> /scripts/after_apache_make_install chmod +x /scripts/after_apache_make_install
You’re all set!