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

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Wed, 2006-05-31 21:08. ::

3.2 Configure Traffic Limits

In the next example we want to give our vhost www.example.com a traffic limit of 100MB per month, and if that limit is exceeded, we want to limit the download speed to 128kbps, max. 5 requests per second and max. 15 open connections:

<VirtualHost 1.2.3.4>
ServerName www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www
CBandLimit 100M
CBandExceededSpeed 128 5 15
CBandScoreboard /var/www/scoreboard
CBandPeriod 4W
</VirtualHost>

The directives are pretty self-explanatory. The CBandPeriod directive specifies after what time the traffic counter is reset to 0.

The next example is pretty similar, but now we don't want the speed to be limited if the traffic is exceeded, no, we get more restrictive and deliver a 503 status page instead:

<VirtualHost 1.2.3.4>
ServerName www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www
CBandLimit 100M
CBandScoreboard /var/www/scoreboard
CBandPeriod 4W
</VirtualHost>

If you want to redirect the user to a URL instead of presenting a 503 error to him, you can do it like this:

<VirtualHost 1.2.3.4>
ServerName www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www
CBandLimit 100M
CBandExceededURL http://www.someisp.com/traffic_exceeded.html
CBandScoreboard /var/www/scoreboard
CBandPeriod 4W
</VirtualHost>

Please note: the CBandExceededSpeed and the CBandExceededURL directives are mutually exclusive. They do not make sense in the same vhost!

After your changes, you must restart Apache:

Debian:

/etc/init.d/apache2 restart

Fedora:

/etc/init.d/httpd restart

Of course, you are free to combine the directives of chapter 3.1 and 3.2 in any way you like.


4 Status Page

To view the current bandwidth limits, usages, users, scoreboards, add the following Location lines to the vhost configuration:

<VirtualHost 1.2.3.4>
ServerName www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www
CBandLimit 100M
CBandExceededSpeed 128 5 15
CBandScoreboard /var/www/scoreboard
CBandPeriod 4W

<Location /cband-status>
SetHandler cband-status
</Location>
<Location /cband-status-me>
SetHandler cband-status-me
</Location>
</VirtualHost>

Restart Apache, and afterwards you can find the status pages under http://www.example.com/cband-status and http://www.example.com/cband-status-me:


5 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Sun, 2006-08-27 12:47.

hi,

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,

Martin