Sunday, August 28, 2011

Apache2 Bandwidth Limiting in Ubuntu Hardy 8.04

Unfortunately there is no libapache2-mod-bw for Ubuntu, so limiting bandwidth used by apache isn’t possible by default. Follow these steps to enable it.
tar xvzf mod_bw-0.8.tgz
cd mod_bw
apxs2 -i -a -c mod_bw.c
You will probably get this error
apxs:Error: Activation failed for custom /etc/apache2/httpd.conf file..
apxs:Error: At least one `LoadModule’ directive already has to exist..
It’s safe to ignore this.
vi /etc/apache2/mods-available/mod-bw.load
LoadModule bw_module /usr/lib/apache2/modules/
vi /etc/apache2/mods-available/mod-bw.conf
BandWidthModule On
BandWidth all 40000
MinBandWidth all 10000
ForceBandWidthModule On
Set permissions
chown www-data /etc/apache2/mods-available/mod-bw*
Activate the module
a2enmod mod-bw
(To deactivate use: a2dismod mod-bw)
Restart apache2
/etc/init.d/apache2 force-reload
Download a file (I suggest doing it remotely to test it), and you should be limited to around 40 kilobytes/second total, with each user guaranteed 10 kilobytes/second. Change this number accordingly.

No comments: