Limit the upload bandwidth of your apache webserver with mod_bw
I've a server at home on a ADSL connection which has 100kBytes/s of upload and 1.2MBytes/s of download as bandwidth.
If someone download at full speed some large file on my web server, my internet connection become unusable.
To avoid this, I start to ask my friends to use a download manager to limit their download speed... but it's somewhat far too tricky for a lot of them...
So I use mod_bw developed by Ivan Barrera http://www.ivn.cl/apache/ (sourceforge : http://bwmod.sourceforge.net/).
Here is a quick way to limit the bandwidth used by Apache :
Install & enable (on Ubuntu):
sudo apt-get install libapache2-mod-bw
sudo a2enmod bw
Configure (your apache virtualhost conf file like /etc/apache2/sites-available/default) :
<virtualhost *:80>
#... other config stuf for the virtual host
BandWidthModule On
ForceBandWidthModule On
BandWidth 192.168.0.0/24 0
BandWidth all 80000
</virtualhost>
Explaination :
- line 1 : Activate the mod for the virtualhost.
- line 2 : Set a directive so that the mod limit the bandwidth on all http request. (you can use an alternate config to limit only some mime type)
- line 3 : set no limit for computer on your local area network.
- line 4 : set a limit to 80KB/s to all other computer
Restart Apache so that the config is loaded and test :
service apache2 restart (or apachectl restart)
Test with Firefox on a large file. From my computer, I've first commented with a heading # the third line (BandWidth 192.168.0.0/24 0) and when it works, I uncommented it.
Comments
I'm really new to Apache stuff, and this configuration is pretty important to me! Thanks.
(you should have a default file at least)
>virtualhost 80:*
It's a mistake I'll correct just after answering you.
it should be virtualhost *:80
where the * stands for 'any ip' (part of apache syntax).
If you replace * by a specific IP, apache2 will listen (serve html pages) only on this IP.
80 is the port.
thank you
If you only do some browsing, 5 ot 10% of your upload bandwith is enough to send the request, the important thing is your download speed.
If you have something like emule, you need to spare more upload bandwith as you need at least 20kb/s to have full download capabilities on emule...
Download:
11061 kbps
Upload:
495 kbps
(1382.6 KB/sec transfer rate)
Upload Speed: 495 kbps
(61.9 KB/sec transfer rate)
so what should i put here:
BandWidth all 80000
80000 is in what?
I've about 110kByte/s of upload...
so you should put 35000 or 50000
(uploadspeed in KB / 2) * 1024;
great thanks, you should update your post to reflect that that value is in bytes and should be accordingly to your upload speed...
thanks for the help...
i've 110kByte/s of upload and I set only to 80kByte/s...
it just depends on how you use your internet connection...
with 30kB/s i'm confortable for sending http request and uploading with emule
upload speed / 2 is wrong, it would be a waste of bandwith in my case as I don't need 55kB/s free to surf and emule
and in case of a low upload speed connection let's say 30kB/s, 15kB/s wouldn't be enough to have a correct emule upload and browsing...
ForceBandWidthModule On
BandWidth 192.168.0.0/24 0
BandWidth all 80000
I have limit only for download, but speed for upload file is not limited ?
first it didn't installed in terminal. so i used synaptic by entering libapache2-mod-bw
installed changed the vhost.
working like a snail
Thanks man
i installed from the synaptic by entering libapache2-mod-bw. im using ubuntu 11.04
now its working like a snail....:P