Bandwidth Limiting in Apache Server
Original Document from: http://www.vttoth.com/bandwidth.htm [thanks Viktor!]
Mod_Bandwidth can be found here: http://www.cohprog.com/v3/bandwidth/download-en.html
edited by D. Slagers for use with the SUn Qube3 [05-10-2004]
At home I have a 4Mbps down and 768Kbps up DSL line connection. This results in 480Kbps download and
70~78Kbps upload. Sometimes a user is hitting my server hard by downloading a file what can consume all
my bandwidth. Therefore I needed a solution.
mod_Throttle was not a solution. 1st the documentation is bad and 2nd: it did not serve my needs.
mod_bandwidth is the solution for me.
Apache 1.3.x (which is what I use) does not have a built-in capability to limit the transfer speed of large downloads, but fortunately, others came to the rescue. Specifically, CohProg Sàrl, a Swiss Internet company that makes an Apache module, mod_bandwidth, available for free.
Here are the steps one has to take to implement bandwidth limiting on a running Apache server.
First, you need to (of course) download the module. Should go without saying. What you download is a single source file, mod_bandwidth.c.
Next, you need to compile this module. On an existing Apache installation, the following line should do the trick:
/usr/sbin/apxs -c ./mod_bandwidth.c -o mod_bandwidth.so
Next, you need to copy mod_bandwidth.so to your libexec directory
For the Qube3 you can copy the file in: /usr/lib/apache/mod_bandwidth.so
This you need to do as root.
Create 3 directories
/var/tmp/apachebw
/var/tmp/apachebw/link
/var/tmp/apachebw/master
then:
chown -R httpd:root apachebw
chmod -R 777 apachebw
(this is working for me)
Next, edit your httpd.conf file. As the first LoadModule line, add the following:
LoadModule bandwidth_module modules/mod_bandwidth.so
For the Qube3 I have removed (or not used the) AddModule line
AddModule mod_bandwidth.c
when restarting the httpd server it gave me the message that it was already added, so I disabled it again.
Then, just before your VirtualHosts blocks, insert the following:
BandWidthModule On
BandWidthDataDir /var/tmp/apachebw/
You can now restart Apache:
/etc/rc.d/init.d/httpd restart
Now you're ready to limit the bandwidth in specific directories (and all their subdirectories) by editing the .htaccess file in them. For instance:
BandWidth 199.166.252 0
BandWidth bandwidth-limit.com 0
BandWidth all 8192
Check the online documentation for more information and extra options. Above is working for me.