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

Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"

Top Level » Apache Related Information

I want to limit the number of connections per IP, or throttle the bandwidth for all clientsLast Modified: Jul 25, 2014, 4:06 pm
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 apache configs.  Edit the file:

nano /etc/httpd/conf/extra/httpd-includes.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

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)
Related Helpfiles
I'm being attacked by a slow-loris attack

© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST