How to Limit IP downloads in Apache using with 'LimitIPConn'
Apache module mod_limitipconn.c, which allows web server administrators to limit the number of simultaneous downloads permitted from a single IP address.
Installing mod_limitipconn.c:
Installing this was quick and easy. Login to your server through shell as the root user.
# wget tar xzvf mod_limitipconn-0.04.tar.gz
# cd mod_limitipconn-0.04
# vi Makefile
Find
APXS = apxs
CHANGE TO:
APXS = /usr/local/apache/bin/apxs
Save
#make
#make install
This adds the module to httpd.conf and backs up the old configuration from httpd.conf.new
# vi /usr/local/apache/conf/httpd.conf
It should have added the following:
LoadModule limitipconn_module libexec/mod_limitipconn.so
and
AddModule mod_limitipconn.c
Now we need to setup the configuration for the site you want to add the limits to. Search the domain you want and go to the configuration for it in httpd.conf
You should be at the part like this:
<VirtualHost IP HERE>
ServerAlias http://www.domain.com domain.com
Add the following configuration that you want, this restricts 2 directories I have on my site to prevent users from downloading more than 1 video at a time, I have 2 separate rules.
<IfModule mod_limitipconn.c>
<Location /videos>
MaxConnPerIP 1
# In this case, all MIME types other than audio/mpeg and video*
# are exempt from the limit check
OnlyIPLimit audio/mpeg video
</Location>
<Location /forums/media/data>
MaxConnPerIP 1
# In this case, all MIME types other than audio/mpeg and video*
# are exempt from the limit check
OnlyIPLimit audio/mpeg video
</Location>
</IfModule>
So my whole entry for the domain looks like this:
<VirtualHost IPHERE>
ServerAlias http://www.domain.com domain.com
ServerAdmin webmaster@domain.com
DocumentRoot /home/domain/public_html
BytesLog domlogs/domain.com-bytes_log
ServerName http://www.domain.com
<IfModule mod_php4.c>
php_admin_value open_basedir "/home/domain:/usr/lib/php:/usr/local/lib/php:/tmp"
</IfModule>
<IfModule mod_limitipconn.c>
<Location /videos>
MaxConnPerIP 1
# In this case, all MIME types other than audio/mpeg and video*
# are exempt from the limit check
OnlyIPLimit audio/mpeg video
</Location>
<Location /forums/media/data>
MaxConnPerIP 1
# In this case, all MIME types other than audio/mpeg and video*
# are exempt from the limit check
OnlyIPLimit audio/mpeg video
</Location>
</IfModule>
User domain
Group domain
CustomLog domlogs/domain.com combined
ScriptAlias /cgi-bin/ /home/domain/public_html/cgi-bin/
</VirtualHost>
Save httpd.conf
Test Apache Configuration
# apachectl configtest start
Make sure it comes back ok without errors
# /scripts/restartsrv_httpd
(In Cpanel servers)
No comments:
Post a Comment