Throttle Apache bandwidth

From BubbaWiki
Jump to: navigation, search

If you use your B3 as a proxy/firewall/home-router as well as a server, you may end up having your server's visitors using all your upload bandwidth. This can affect the quality of the access of whoever is behind the home-router. This wouldn't occur in a usual case of people browsing on the standard web interface of the B3, but it can occur if you have a few big media files on it (see for instance forum.excito.net/viewtopic.php ). In that case, you may want to throttle the bandwidth used by the Apache2 server, in order to leave ressources for the users behind the home-router. A method for doing so is to use a module called "libapache2-mod-bw".


  • First, as root, we'll install this package:
apt-get install libapache2-mod-bw
  • Some documents indicate that we should then load this module by typing:
a2enmod bw

(personally, I got a message saying it was already loaded, but it didn't seem to do anything negative, so just in case, I've kept this step)

  • Now, we need to configure Apache to tell it what limits we want to set:
nano /etc/apache2/sites-enabled/bubba
  • Inside the editor, you need to add the following lines (changing the bandwidth to the desired maximum) just before both </VIRTUALHOSTS> (there's one for HTTP and another for HTTPS):
# turn bw limitation on
BandwidthModule On

# force limitation on every request
ForceBandwidthModule On

# limit to 250kB/s
Bandwidth all 250000
  • Finally, let's restart the Apache server!
/etc/init.d/apache2 restart


There you are. You should now have a throttled Apache server, which will allow your home users to continue surfing. Note that the module bw comes with plenty other options (limiting only for certain types of files, limiting per user, ...).