• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » How to Install and Configure mod_evasive on Ubuntu for WordPress

By Abhishek Ghosh May 28, 2023 7:07 pm Updated on May 28, 2023

How to Install and Configure mod_evasive on Ubuntu for WordPress

Advertisement

mod_evasive is an Apache server module which provides action in the event of a Denial of Service attack. It is also can be configured to fail2ban, firewalls and routers. However, using with WordPress is not always easy. The module can lead dysfunction of certain plugins and backend administration.

mod_evasive is easier to configure and maintain/monitor than modsecurity. This person is the developer of mod_evasive:

Vim
1
2
https://github.com/jzdziarski
https://www.zdziarski.com/blog/?cat=14

I may cause too many false blocks. You need to make the settings quite liberal, check the log to make sure that your visitors or search engine bots are not getting blocked. It is particularly good when you are not closer to your computing device to SSH and check what is happening.

Advertisement

---

This module can cause performance penalties on an active server. Run webpagetest.org’s test to make sure that the site speed has not been too much slower.

 

Steps to Install mod_evasive on Ubuntu Server

 

Your server may run MPM Event and PHP-FPM or default MPM Prefork mod_php. Run these commands:

Vim
1
2
3
apt-get update && apt-get upgrade -y
apt-get install apache2-utils -y
apt-get install libapache2-mod-evasive -y

You will face a prompt asking you to configure a Postfix mail server for email notifications. You can select the option “Internet site” and continue the installation. mod_evasive uses /bin/mail for sending email alerts and you need to have a mail server installed and working to receive email notifications. You can skip the mail server setup for now. It is better to configure it later rather than skip the email notification.

Now, if you run this command:

Vim
1
apachectl -M | grep evasive

You’ll get the output:

Vim
1
evasive20_module (shared)

Do not activate the module before reading the next sub-header.
The module’s name is evasive, so these commands will work to activate and deactivate the module:

Vim
1
2
3
4
## apache2 enable module
a2enmod evasive
## apache2 disable module
a2dismod evasive

Before enabling and disabling, always run:

Vim
1
apachectl configtest

…and reload settings in this way:

Vim
1
/etc/init.d/apache2 reload

These will avoid facing this kind of odd error – Config variable ${APACHE_RUN_DIR} is not defined.

For the common main modules of Apache (such as rewrite), you can restart or reload in any you want. The users of these modules are not as many as the common modules. They may have minor bugs.

 

How to Configure mod_evasive for WordPress

 

The configuration file of mod_evasive is located at /etc/apache2/mods-enabled/evasive.conf. By default, there will be examples of too many restrictive settings and whitelisting will not be done. Open the file:

Vim
1
nano /etc/apache2/mods-enabled/evasive.conf

This is a liberal setting which you can try:

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<IfModule mod_evasive20.c>
DOSWhiteList 127.0.0.1
DOSWhiteList 127.0.0.*
# DOSWhiteList <your-server-ip>
# DOSWhiteList <your-ip>
 
    DOSHashTableSize    32768
    DOSPageCount        20
    DOSSiteCount        50
    DOSPageInterval     10
    DOSSiteInterval     10
    # kept lower value for your testing
    DOSBlockingPeriod   10
 
    # DOSSystemCommand "su - someuser -c '/sbin/... %s ...'"
    DOSLogDir           "/var/log/mod_evasive"
</IfModule>

DOSPageCount is the limit for the number of requests for the same page by an IP address, per second set by DOSSiteCount.
DOSPageCount below 10 catches false positives. 20 to 30 is an acceptable value.
DOSSiteCount requires to be 50 to 100.

DOSHashTableSize default value is 3097. Setting it to 32768 will make the server faster but will suck RAM. You should check the memory consumption.

If some plugins at WordPress admin disturb you, then increase the values.

Create the log directory. On Ubuntu, the default user for apache2 is www-data (you can check it by running ps aux | grep apache command):

Vim
1
2
3
4
5
mkdir -p /var/log/mod_evasive
## Check the user name
ps aux | grep apache
# give permission to write
chown www-data:www-data /var/log/mod_evasive

Run:

Vim
1
apachectl configtest

…and reload settings:

Vim
1
/etc/init.d/apache2 reload

 

Test With a Script

 

There is a default test script here:

Vim
1
/usr/share/doc/libapache2-mod-evasive/examples/test.pl  

But that requires adjustment, change the site address on this line PeerAddr=> "your-site.com:443" from your-site.com to your’s one. Also I have changed for(0..100) to for(0..200):

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/perl
 
# test.pl: small script to test mod_dosevasive's effectiveness
 
use IO::Socket;
use strict;
 
for(0..200) {
  my($response);
  my($SOCKET) = new IO::Socket::INET( Proto   => "tcp",
                                      PeerAddr=> "your-site.com:443");
  if (! defined $SOCKET) { die $!; }
  print $SOCKET "GET /?$_ HTTP/1.0\n\n";
  $response = <$SOCKET>;
  print $response;
  close($SOCKET);
}

I have kept these files in this GitHub repo. You can wget the script, open, edit, chmod and execute:

Vim
1
2
3
4
5
cd ~
wget https://raw.githubusercontent.com/AbhishekGhosh/mod_evasive-settings-for-WordPress/main/test.pl
nano test.pl
chmod +x test.pl
sudo perl test.pl

It will give you either 403 error or 400 error. This is a test result on a test server:

How to Install and Configure mod_evasive on Ubuntu for WordPress

400 error is coming out of other settings before mod_evasive can handle the request. Disable other such system and test.

Try to increase the values facing errors. It is better to keep this module active.

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to How to Install and Configure mod_evasive on Ubuntu for WordPress

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Join/Merge Multiple Log Files For Big Data Analysis

    Here Are The Ways To Join/Merge Multiple Log Files For Big Data Analysis, Store Them To OpenStack Based Cloud Storage And Delete Old Files.

  • How to Set up Free Hotmail, Yahoo!, GMail, AOL and other e-mail in Windows Live mail

    Tutorial with screenshots to show how to setup Windows Live Mail to check free email accounts like Free Hotmail, Yahoo!, GMail, AOL and other e-mail accounts.

  • Harden Apache2 Server’s Security (Ubuntu 16.04 LTS)

    Here Is A Detailed Guide On How To Harden Apache2 Server’s Security On Ubuntu 16.04 LTS. This Is Cloud, Dedicated & Virtual Dedicated Server.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy