Bandwidth restriction – How to limit the download speed for your visitors a terrible thing when you haven’t a very high speed upload rate on your personal server at home or VPS or even cheap dedicated server, and that 1 or few users are saturating your bandwidth (By genuinely “consuming” your content such as photos, videos, or file to share, … or even by some script kiddies downloading in loop one of your picture from your blog or so).


The best thing is obviously….to have a good upload 🙂 but as you may not be able to decide that, the next good idea is to set a bandwidth speed limit.


The Mod_bw module of Apache can help you to set restriction per Virtualhost (Different websites or services), per IP, per type of file and even per file’s size.



To install the mod_bw module, just type:

sudo apt-get install libapache2-mod-bw

and enable it if not done automatically at the end of the installation

sudo a2enmod bw



You can directly write your configuration inside the vhost of your choice.

If for example you want to set a limit per visitors, type of file, and size of file for your website “myblog” but without restriction on any request from your local network, edit the related virtualhost:

sudo nano /etc/apache2/sites-enabled/myblog

and add the following at the end, before the :

BandWidthModule On  ### Enable the module for this virtualhost
ForceBandWidthModule On  ### Force all connections to go through the module
BandWidth 0  ### All the connections from the IP will have no restriction
Bandwidth all 50000  ### All the connections will be limited to 50kb/s
LargeFileLimit * 100000 30000  ### All the files above 100Mb will be limited to 30kb/s
LargeFileLimit .avi 1 20000  ### All the .avi files will be limited to 20kb/s

Obvisouly you can set as you wish. Me I used to filter only 2 levels, Bandwidth All and LargeFileLimit *

Save your file (CTRL+X, then Yes) and restart apache

sudo /etc/init.d/apache2 restart

Loves to discover web-based apps to install on his own server@home and write articles about it


Add a comment