Mod limitipconn

From CPanelDirect

Jump to: navigation, search

mod_limitipconn.c allows web server administrators to limit the number of simultaneous downloads permitted from a single IP address. Its url is [1]

This module is useful for lowering the load of apache due to high load. This is useful when many ips are flooding apache making iptables not useful. You need to know the domain name getting flooded and be able to edit /usr/local/apache/conf/httpd.conf

This is for apache1 only. Check their URL for an apache2 port.


Get the latest mod_limitipconn at [2]

wget http://mirror.trouble-free.net/sources/mod_limitipconn-0.04.tar.gz
tar -zxf mod_limitipconn-0.04.tar.gz
cd mod_limitipconn-0.04
/usr/local/apache/bin/apxs -cia mod_limitipconn.c

The output of the command will look like:

root@server [/usr/src/mod_limitipconn-0.04]# /usr/local/apache/bin/apxs -cia mod_limitipconn.c
gcc -DLINUX=22 -DHAVE_SET_DUMPABLE -I/usr/include/gdbm -DMOD_SSL=208128 -DUSE_HSREGEX -DEAPI -fpic 
-DSHARED_MODULE -I/usr/local/apache/include  -c mod_limitipconn.c
gcc -shared -o mod_limitipconn.so mod_limitipconn.o
[activating module `limitipconn' in /usr/local/apache/conf/httpd.conf]
cp mod_limitipconn.so /usr/local/apache/libexec/mod_limitipconn.so
chmod 755 /usr/local/apache/libexec/mod_limitipconn.so
cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak
cp /usr/local/apache/conf/httpd.conf.new /usr/local/apache/conf/httpd.conf
rm /usr/local/apache/conf/httpd.conf.new

The following line needs to be added to /usr/local/apache/conf/httpd.conf, inside a virtual host

<IfModule mod_limitipconn.c>
   <Location />
       MaxConnPerIP 3
       # exempting images from the connection limit is often a good
       # idea if your web page has lots of inline images, since these
       # pages often generate a flurry of concurrent image requests
       NoIPLimit image/*
   </Location>
</IfModule>


Example:

<VirtualHost IP:80>
  ServerAlias domain.com
  ServerAdmin webmaster@domain.com
  DocumentRoot /home/domain/public_html
  BytesLog domlogs/domain.com-bytes_log
  User iowncail
  Group iowncail
<IfModule mod_php4.c>
php_admin_value open_basedir "/home/domain/:/usr/lib/php:/usr/local/lib/php:/tmp"
</IfModule>
<IfModule mod_php5.c>
php_admin_value open_basedir "/home/domain/:/usr/lib/php:/usr/local/lib/php:/tmp"
</IfModule>
  ServerName www.domain.com
<IfModule mod_limitipconn.c>
   <Location />
       MaxConnPerIP 3
       # exempting images from the connection limit is often a good
       # idea if your web page has lots of inline images, since these
       # pages often generate a flurry of concurrent image requests
       NoIPLimit image/*
   </Location>
</IfModule>
  User domain
  Group domain
  CustomLog /usr/local/apache/domlogs/domain.com combined
  ScriptAlias /cgi-bin/ /home/domain/public_html/cgi-bin/
</VirtualHost>


Then restart apache with the command:

/scripts/restartsrv_httpd

Update for New Easy Apache

Cpanel will overwrite httpd.conf changes now. To do the same thing on the new easy apache do the following:

mkdir -p /usr/local/apache/conf/userdata/std/1/domain/domain.com

Make a file called custom.conf and in it add

   <Location />
       MaxConnPerIP 3
       # exempting images from the connection limit is often a good
       # idea if your web page has lots of inline images, since these
       # pages often generate a flurry of concurrent image requests
       NoIPLimit image/*
   </Location>

Then run

/scripts/ensure_vhost_includes --user=domain

Where domain is the account username and domain.com is the account domain name. Then restart apache.

Personal tools