mod_slotlimit

mod_slotlimit is an Apache module that using dynamic slot allocation algorithm and static rules, can manage resources used for each running site.

1. Installation (Debian Etch/Lenny/Squeeze)

In order to compile mod_slotlimit, you will need to have apxs2 (APache eXtension tool) installed and configured with Apache.

The follow command will install it:

apt-get install apache2-prefork-dev

Now we download the source package present at http://sourceforge.net/projects/mod-slotlimit/ or download it using wget application and this direct link to the repository:

wget http://downloads.sourceforge.net/project/mod-slotlimit/mod-slotlimit/1.3/mod_slotlimit-1.3.tar.gz

Next open archive, compile and install module with those commands:

tar zxvf mod_slotlimit-1.3.tar.gz
cd mod_slotlimit-1.3
make
make install

Add in the main config file of your web server the following command in order to load mod_slotlimit module.

vi /etc/apache2/httpd.conf

LoadModule slotlimit_module /usr/lib/apache2/modules/mod_slotlimit.so

2. Configuration

Before we are able to write our configuration, we should known what directives are supported by this module.

For more information read mod_slotlimit’s documentation:

AvailableSlotsPercent

Syntax: AvailableSlotsPercent number
Default: 0

Percentage of apache slots available in order to set any restrictions.
Setting it to 0 dynamic slot allocation algorithm will be deactivated.
When has remained free the specified percentage of apache slots, module
start to manage incoming connections, penalizing sites that are monopolizing
the resources of the server.

N.B. Before activating this option check that the apache scoreboard display
correct vhost name of the running sites. In order to make this you can
activate (momentarily) mod_status and connect to http://yourserver/server-status.
If Vhost hostname do not display correctly the name of the sites visited
sets up to "On" the directive "ForceVhostName" before using "AvailableSlotsPercent".

MaxConnectionsPerSite

Syntax: MaxConnectionsPerSite number
Default: No Limit

Max connections for each running site

N.B. Like for "AvailableSlotsPercent" if Vhost hostname do not display correctly
the name of the sites visited sets up to "On" the directive "ForceVhostName".

ClientIpLimit

Syntax: ClientIpLimit number
Default: 40

Number of maximum simultaneous connection per IP.

ForceVhostName

Syntax: ForceVhostName On|Off
Default: Off

Force vhost hostname in scoreboard. Vhost hostname do not match site
visited under some conditions, for example with some mass virtual hosting technique.
In order to check that this is not your case you can use mod_status.
Setting this directive to On, mod_slotlimit will overwrite vhost hostname
in apache scoreboard.

CustomErrMsg

Syntax: CustomErrMsg "My custom error message"
Default: "Blocked by mod_slotlimit. More information about this error may be available in the server error log."

A custom error message that allows you to replace default error message with one you create

CustomLimitsFile

Syntax: CustomLimitsFile /path/to/file
Default: No Value

Using this directive you can specify limits customized for each running site,
penalizing or privileged it. In the file should be stored (line by line) the
site name and the number of usable slots. You can add comments by using the '#'
character. The file format is as follows:

..
..
www.sitename1.it 10
# this is a comment
www.site2.com 35
..
..

Now we open config file of our web server in order to write the configuration:

vi /etc/apache2/apache2.conf

[...]
<IfModule mod_slotlimit.c>
AvailableSlotsPercent 10
MaxConnectionsPerSite 40
ClientIpLimit 30
CustomLimitsFile /etc/apache2/mod_slotlimit.rules
ForceVhostName On
</IfModule>

[...]

Finally we restart Apache:

/etc/init.d/apache2 restart