Limit Bandwidth per vHost in Apache2 (on Debian/Lenny)
English, Howto, Linux, debian February 14th, 2009This HowTo somehow is Debian specific, although the configuration of the module will work the same for all *nix distributions. It will illustrate how to limit bandwidth on a vHost basis using the Bandwidth Mod by Ivan Barrera written for the Summer Of Code event. First of all you will have to install the libapache2-mod-bw package on your system.
apt-get install libapache2-mod-bw
Now enable the module by using the a2enmod command
a2enmod bw
The next step is to configure the vHost according to your desires. In this case I choose to limit the bandwidth to 200kb/s for every request on a per user basis. Note that the bandwidth limit should be specified in byte, meaning that you have to multiply the kB value by 1024 (_not_ 1000) to get an accurate result, hence 200kB/s will be 204800 byte, rather than 200000 byte.
<VirtualHost *:59439>
ServerName foo.de
ServerAlias www.foo.de
# turn bw limitation on
BandwidthModule On
# force limitation on every request
ForceBandWidthModule On
# limit to 200kB/s
Bandwidth all 204800
DocumentRoot /home/siyb/www/dltoke
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/toke.pem
</VirtualHost>
If you are looking for a more distinct way to limit the vHost’s bandwidth you should really check out all available directives for the bw mod here.






June 25th, 2009 at 23:52
hi, i’ve tryied to use apt-get install libapache2-mod-bw
but it doesn’t work …
July 4th, 2009 at 15:48
@Alfredo:
Please be more specific, which version of Debian are you using?
August 5th, 2010 at 12:26
Thank you this nice short easy tutorial. I managed to integrate this long-requested module to ehcp using this tutorial.
thank you all.