Limit Apache Bandwidth with mod_bw
Apache will normally serve a file at the maximum speed possible. I needed to rate limit an apache server to act as a fake QOS to ensure the line would not be saturated when serving large files. This is incredibly easy to do with mod_bw. First we need to install and enable mod_bw
apt-get install libapache2-mod-bw
a2enmod bw |
Then it is a simple task of specifying the limits in you virtualhost conf file.
BandWidthModule On ForceBandWidthModule On BandWidth 10.40.0.0/16 0 BandWidth all 1500000 |
The above enables the module, forces the module for all apache traffic and then finally we dont restrict the local network but restrict everyone else to 150KB/s.
Then simply restart apache
/etc/init.d/apache2 restart |
You can test by commenting out the line for the local network, restarting apache again and then try to download a large file and you should notice the browser is only about to download at around 150KB/s.