I want to limit the number of connections per IP, or throttle the bandwidth for all clients

If you wish to have some caps for the number of connections and amount of bandwidth a client can use, mod_bw is a simple modules for this.

To install it, run the following:

cd /root
wget http://files.directadmin.com/services/custombuild/mod_bw-0.92.tgz
mkdir mod_bw
cd mod_bw
tar xvzf ../mod_bw-0.92.tgz
/usr/sbin/apxs -i -a -c mod_bw.c

which will compile the module and load it into the main httpd.conf for you.

Now, you must turn it on and set it up in the main httpd.conf.  Edit the file:

nano /etc/httpd/conf/httpd.conf

and after the line:

LoadModule bw_module          /usr/lib/apache/mod_bw.so

add more code that looks like this

BandWidthModule On
ForceBandWidthModule On
BandWidth all 102400000
MinBandwidth all -1
MaxConnection all 3
#<Location /modbw>
#    SetHandler modbw-handler
#</Location>

The above code allows a maximum number of 3 connections per IP address.
The bandwidth limit is set to 100 Meg per second
A bandwidth value must be set in order for the IP limit to work.  Setting an unlimited value will cause the module to ignore the IP connection count, hence must be a number, hence the large number which is unlikely to be hit.

Don't forget to restart apache after making the changes, eg:

/etc/init.d/httpd restart


If you wish to monitor your connections and transfer rates, you can remove the # characters in front of the 3 Location lines, and restart apache.  Access any IP or domain with /modbw to get details on your connections.  (you can change /modbw to something else if you wish, or use the Allow/Deny options to make it more secure)


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 17595