Manage Apache Download Speed And Traffic Limits With mod_cband - Page 2

3 Apache Configuration

You can find all configuration directives on mod_cband's documentation page; I will describe the most important ones here.

In this chapter I assume we have a web site on the IP address with the document root /var/www and the following vhost configuration:

DocumentRoot /var/www

Please note: It is important that your vhost includes the ServerName directive (e.g. ServerName and that your mod_cband directives come after that directive, otherwise you will get a warning like this when you restart Apache:

Starting httpd: [Mon May 29 18:05:33 2006] [warn] Invalid command 'CBandSpeed', undefined virtualhost name

You can use the following units in the mod_cband directives:

Transfer speeds:

  • kbps: 1024 bits per second
  • Mbps: 1024*1024 bits per second
  • Gbps: 1024*1024*1024 bits per second
  • The default is kbps.

Transfer quotas:

  • K: 1000 bytes
  • M: 1000*1000 bytes
  • G: 1000*1000*1000 bytes
  • Ki: 1024 bytes
  • Mi: 1024*1024 bytes
  • Gi: 1024*1024*1024 bytes
  • The default is K.

Time periods:

  • S: seconds
  • M: minutes
  • H: hours
  • D: days
  • W: weeks
  • The default is S.

First we add the following two directives to the global Apache configuration (not to the vhost from above!). They are needed to improve mod_cband's performance.


vi /etc/apache2/apache2.conf


vi /etc/httpd/conf/httpd.conf

CBandScoreFlushPeriod 1
CBandRandomPulse On

Now we create the scoreboard directory for our vhost, /var/www/scoreboard. The directory must be writeable by the Apache user:


mkdir /var/www/scoreboard
chown www-data:www-data /var/www/scoreboard/


mkdir /var/www/scoreboard
chown apache:apache /var/www/scoreboard/

3.1 Configure Download Speed

Now let's say we want to limit the download speed. We can do it like this:

DocumentRoot /var/www
CBandSpeed 1024 10 30
CBandRemoteSpeed 20kb/s 3 3

The CBandSpeed directive limits the overall Apache performance for the vhost to a speed of 1024kbps, max. 10 requests per second and max. 30 open connections.

The CBandRemoteSpeed is like the CBandSpeed directive, but it sets limits for any individual user (as compared to the overall settings made by CBandSpeed).

After your changes, you must restart Apache:


/etc/init.d/apache2 restart


/etc/init.d/httpd restart

Share this page:

15 Comment(s)

Add comment


From: Anonymous at: 2006-06-03 20:10:48


From: Anonymous at: 2006-06-01 15:42:21

The cband Apache2 module is available from Debian's package sources if you are running testing (etch) or unstable (sid). apt-get install libapache2-mod-cband

From: Anonymous at: 2006-06-07 20:54:35

libapache2-mod-cband is on for sarge.

You do not need to recompile.

From: Anonymous at: 2008-10-01 23:29:34

I have a test Apache 2.2 server on Windows 2003, is it poddible to get mod_cband to work on it?



From: Anonymous at: 2006-06-01 22:29:09

There is also a package for mod_cband in Fedora. Just install it with:

yum install mod_cband

From: Paki at: 2011-02-18 21:32:23


From: Anonymous at: 2006-06-02 13:34:26

Considering the majority of Apache installations are still using Apache 1.X, it's a shame that mod_cband isn't also available for Apache 1.X. I guess that the output filtering functionality of Apache 2.X (far superior to 1.X's) has caused this - one "workaround" might be to put an Apache 2.X reverse proxy in front of your (now backend) Apache 1.X server...

From: bahram at: 2011-01-07 10:53:32

hello, is there anyway to do global limitation for all accounts at once? I have about 500 account and I can not add limitation entry one by one.

From: Anonymous at: 2011-08-08 05:06:34

how to install mod_cband on windows 7?

From: Wedesign Marbella at: 2009-06-11 08:53:45


 What would be the configuration to allow a site with only 80Gb per month?

Thanks in advance,

From: Lord Readman at: 2009-07-27 20:39:29

In response to Wedesign Marbella

#the scorebord of the virtual host
CBandScoreboard /var/www/scoreboard/site.scoreboard
#this would set the limit to 80GB
CBandLimit 80G
#this is the period of 30days (set to 31 if you wish)
CBandPeriod 30D
#if 80G is exceeded give everyone a 509 Bandwidth Exceeded Error.
CBandDefaultExceededCode 509

 Of course you can tailor your config to your custom requirements.

From: Wedesign Marbella at: 2009-08-06 14:34:16

Many thanks

From: Anonymous at: 2009-10-08 11:47:37

Hello, and thank you for writing this text.

How can I limit ips in downloads. ex: every ip can only download one time.

From: Anonymous at: 2013-04-10 18:07:52

I want use mod_cband with mod_proxy(apache2 with tomcat cluster). Any one has idea?

From: Anonymous at: 2006-08-27 11:47:45


accoridng the manual for cband the  CBandScoreboard is a path to a file. See bellow:

Name     CBandScoreboard
Description     Specifies virtualhost's scoreboard file
Context     <Virtualhost>
Syntax     CBandScoreboard path

in your examples it's defined as directory:

mkdir /var/www/scoreboard
chown apache:apache /var/www/scoreboard/

CBandScoreboard /var/www/scoreboard

which is not true!

you should touch the file not do mkdir. 

 Best regards,