Easy bandwidth limiting in Apache2

Posted by on September 19, 2008 under Uncategorized |

I ran into a problem the other day… too many downloads of a large VMWare image I had shared.  It swamped my connection and made the server inaccessible.  So I had to quickly put in a bandwidth limiter, and thought I’d share how easy it is to do:

I am using mod_bandwidth.  There are several other Apache2 modules for managing bandwidth.  This one is a great quick fix.  In fact, I usually install this by default, but unfortunately forgot to on this website - until my bandwidth was maxed.  I highly recommend installing something along these lines to protect your system from this problem.

My system is Ubuntu Server and Apache2

This is simple to implement:
- Grab the latest version of the source code
- Extract and compile the Apache module
- change apache2.conf

To begin:

Find the latest source code download link at: http://ivn.cl/#bandwidth  Currently it is version 0.8

In a Terminal windows, run these commands in a temp folder:

sudo su
apt-get install apache2-threaded-dev
cd /tmp
wget http://ivn.cl/files/source/mod_bw-0.8.tgz
tar xvzf mod_bw-0.8.tgz
cd mod_bw

note: you may get an error after running this next command - you can ignore it

apxs2 -i -a -c mod_bw.c

nano /etc/apache2/apache2.conf

add the following to the top of the file

LoadModule bw_module /usr/lib/apache2/modules/mod_bw.so
BandWidthModule On
BandWidth all 1000000
MinBandWidth all 100000
ForceBandWidthModule On

This will limit the apache server to 1 Mb of bandwidth with each connections getting at least 100k

Add A Comment