by siyb

This 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.