How-To - Bandwidth Limiter For Apache2 (mod_bw)

charliecreed

Verified User
Joined
Feb 26, 2006
Messages
56
Tested on Debian

You can use mod_bw on apache2 to limit the speed of which files get uploaded.

cd /root/
wget http://bwmod.sourceforge.net/files/mod_bw-0.7.tgz
tar -zxvf mod_bw-0.7.tgz
cd mod_bw
apxs -i -a -c mod_bw.c

That's mod_bw installed, now you just have to configure the virtual templates.

Examples:
Limit every user to a max of 10Kb/s on a vhost :

<Virtualhost *>
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 10240
MinBandwidth all -1
Servername www.example.com
</Virtualhost>


Limit al internal users (lan) to 1000 kb/s with a minimum of 50kb/s , and
files greater than 500kb to 50kb/s.

<Virtualhost *>
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 1024000
MinBandwidth all 50000
LargeFileLimit * 500 50000
Servername www.example.com
</Virtualhost>


Limit avi and mpg extensions to 20kb/s.

<Virtualhost *>
BandwidthModule On
ForceBandWidthModule On
LargeFileLimit .avi 1 20000
LargeFileLimit .mpg 1 20000
Servername www.example.com
</Virtualhost>


Using it the "right" way, with output filter by mime type (for text)
to 5kb/s:

<Virtualhost *>
BandwidthModule On
AddOutputFilterByType MOD_BW text/html text/plain
Bandwidth all 5000
Servername www.example.com
</Virtualhost>

Once configured virtual hosts you will have to restart httpd:

Redhat/Fedora: service httpd restart
Debian: /etc/init.d/httpd restart

Have fun :)
 
Last edited:
look like ....can't work....
after i added what you post in my httpd.conf

also,can i just limit a VirtualHost 's bandwidth?
 
clbbhk said:
look like ....can't work....
after i added what you post in my httpd.conf

also,can i just limit a VirtualHost 's bandwidth?

You don't have to add anything to you're httpd.conf - You add the configuration which I gave you to VirtualHosts!!
 
charliecreed said:
You don't have to add anything to you're httpd.conf - You add the configuration which I gave you to VirtualHosts!!
add it in /CMD_CUSTOM_HTTPD?domain=XXXX?
i try to add

BandwidthModule On
ForceBandWidthModule On
Bandwidth all 10240
MinBandwidth all -1
Servername XXX..........................

to a Virtualhost~~but it also ca't limit the BandWidth of it
 
Last edited:
clbbhk said:
add it in /CMD_CUSTOM_HTTPD?domain=XXXX?
i try to add

BandwidthModule On
ForceBandWidthModule On
Bandwidth all 10240
MinBandwidth all -1
Servername XXX..........................

to a Virtualhost~~but it also ca't limit the BandWidth of it

Configuration: /usr/local/directadmin/data/users/USERNAME/httpd.conf

You should add it through SSH. This is a configuration of what we have for a whole virtual vhost:

web0:/usr/local/directadmin/data/users/liam# cat httpd.conf
# Auto generated apache config file by DirectAdmin version 1.27.5
# Modifying this file is not recommended as any changes you make will be
# overwritten when the user makes any changes to his/her website

# Frontpage requires these parameters in every httpd.conf file or else
# it won't work.
ServerRoot /etc/httpd


<VirtualHost 194.24.188.23:80>

ServerName www.liam.fastfrag.co.uk
ServerAlias www.liam.fastfrag.co.uk liam.fastfrag.co.uk
ServerAdmin [email protected]
DocumentRoot /home/liam/domains/liam.fastfrag.co.uk/public_html
ScriptAlias /cgi-bin/ /home/liam/domains/liam.fastfrag.co.uk/public_html/cgi-bin/

UseCanonicalName OFF

BandwidthModule On
ForceBandWidthModule On
LargeFileLimit .avi 1 200000
LargeFileLimit .mpg 1 200000
LargeFileLimit .exe 1 200000
LargeFileLimit .rar 1 200000
LargeFileLimit .zip 1 200000
MinBandWidth all 30000


SuexecUserGroup liam liam
CustomLog /var/log/httpd/domains/liam.fastfrag.co.uk.bytes bytes
CustomLog /var/log/httpd/domains/liam.fastfrag.co.uk.log combined
#ErrorLog /var/log/httpd/domains/liam.fastfrag.co.uk.error.log

<Directory /home/liam/domains/liam.fastfrag.co.uk/public_html>
Options +Includes +Indexes
IndexOptions +FancyIndexing +FoldersFirst
php_admin_flag engine ON
php_admin_flag safe_mode OFF
php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f [email protected]'
</Directory>



php_admin_value open_basedir /home/liam/:/tmp/:/var/www/:/usr/local/lib/php/:/etc/virtual/

</VirtualHost>

This limits different file extensions to different speeds, however use the examples I showed in the post above this one for more bandwidth settings.
 
undefined symbol: apr_atomic_cas

am install the module correctly, but when i add the configuration option to vhost configs i get an error "undefined symbol: apr_atomic_cas". When that happens, i just open the file mod_bw.c and change the following:

/* Compatibility for ARP < 1 */
#if (APR_MAJOR_VERSION < 1)
#define apr_atomic_inc32 apr_atomic_inc
#define apr_atomic_dec32 apr_atomic_dec
#define apr_atomic_add32 apr_atomic_add
#define apr_atomic_cas32 apr_atomic_cas
#define apr_atomic_set32 apr_atomic_set
#endif

to:

/* Compatibility for ARP < 1 */
/*
#if (APR_MAJOR_VERSION < 1)
#define apr_atomic_inc32 apr_atomic_inc
#define apr_atomic_dec32 apr_atomic_dec
#define apr_atomic_add32 apr_atomic_add
#define apr_atomic_cas32 apr_atomic_cas
#define apr_atomic_set32 apr_atomic_set
#endif
*/

and now i don't have the error, but the module not really limit the Bandwidth
what i need to do ?
 
Back
Top