Modern browsers use multiple connections in order to download content from a website such that limiting the connections to a website is usually not the preferred way to throttle traffic. Nevertheless, Apache is a comprehensive web-server that does not only serve pages, but can also offer web-services such as WebDAV, SVN, etc… In such cases, it might be preferable to restrict the number of connections per IP address.
We are going to use the mod_limitipconn2 Apache module. On some distributions the module is available but on some others (such as Debian), the module will have to be compiled. In order to do that, we will need to install the apache2-dev
package:
aptitude install apache2-dev
After that, retrieve the source:
wget -c http://dominia.org/djao/limit/mod_limitipconn-0.24.tar.bz2
and decompress it:
tar -jcvf mod_limitipconn-0.24.tar.bz2
Change directory to the decompressed directory and run:
make
followed by:
make install
to install the module.
After installation, the module can be enabled on Debian by issuing:
a2enmod limitipconn
or, by adding the line:
LoadModule limitipconn_module lib/apache/mod_limitipconn.so
to the Apache configuration.
Suppose that you have a virtual host serving SVN files. To limit the access to the directory, locate the stanza Location
in your virtual host file, for example:
<Location /svn> DAV svn SVNParentPath /opt/svn </Location>
and change the contents of the Location
body to something like:
<Location /svn> DAV svn SVNParentPath /opt/svn <IfModule mod_limitipconn.c> MaxConnPerIP 5 </IfModule> </Location>
which will limit the connections to that location to 5 concurrent accesses per IP address.
For more settings, you can consult the README
file distributed with the limitipconn2
module.