About the module
mod_cband is an Apache 2 module provided to solve the problem of limiting users’ and virtualhosts’ bandwidth usage. The current versions can set virtualhosts’ and users’ bandwidth quotas, maximal download speed (like in mod_bandwidth), requests-per-second speed and the maximal number of simultaneous IP connections (like in mod_limitipconn)
I advise using mod_cband by hosting companies, which would like to limit data transfer for their users, such as “10 Gb of traffic per month”. There already exists the mod_curb module, which can limit data transfers, but it doesn’t work with virtualhosts and Apache 2, so I wrote my own module fully compatible with Apache 2 API and supporting per-user and per-virtualhost bandwidth limiting
FreeBSD ports path and pkg-descr info
/usr/ports/www/mod_cband
mod_cband is an Apache 2 module provided to solve the problem of limiting virtualhosts bandwidth usage. When the configured virtualhost’s transfer limit is exceeded, mod_cband will redirect all further requests to a location specified in the configuration file.
¼òÒ룺
mod_cbandÊÇÒ»¸öͨ¹ýApache 2Ä£¿éÀ´½â¾öÏÞÖÆÓû§ºÍÐéÄâÖ÷»ú´ø¿íÎÊÌâµÄÓ¦Ó㬵±Ç°°æ±¾¿ÉÒÔµ÷ÕûÐéÄâÖ÷»úºÍÓû§´ø¿íÏ޶×î¸ßÏÂÔØËÙ¶È(like in mod_bandwidth),ÿÃë·ÃÎÊÇëÇóËٶȺÍ×î¸ß²¢·¢·ÃÎÊipÁ¬½ÓÊý(like in mod_limitipconn)¡£
ÎÒ¸æËßÖ÷»ú·þÎñÌṩÉÌʹÓÃmod_cband£¬ÏëÒªÏÞÖÆËûÃÇÓû§Êý¾Ý´«Ê䣬Ïñ“ÿÔÂ10 GbÁ÷Á¿”ÕâÑù¡£µ«ÒÑÓÐÁËmod_curbÄ£¿é£¬¿ÉÒÔÏÞÖÆÁ÷Á¿£¬µ«ÎÞ·¨¹¤×÷ÔÚÐéÄâÖ÷»úºÍApache 2Ï£¬ËùÒÔÎÒдÁË×Ô¼ºµÄÄ£¿éÍêÈ«ÊʺÏÓÚApache 2 APIͬʱ֧³ÖÿÓû§ºÍÿÐéÄâÖ÷»ú´ø¿íÏÞÖÆ¡£
ºÃÁË£¬Ëµµ½ÕâÀïÎÒÏëÕâ¸öÄ£¿éµÄ¾«ËèÖ®´¦ÔÚÓÚÍêÃÀµÄÖ§³ÖApache 2²¢ÊµÏÖÁËÔÓÐÁ½¸öÄ£¿éµÄÈ«²¿¹¦ÄÜ£¨2in1£©ÇÒÖ§³ÖÿÓû§ºÍÿÐéÄâÖ÷»ú´ø¿íÏÞÖÆ¡£ÕâÔÚ½øÐÐwebƽ̨ӦÓÃÓëÕûºÏ֮ʱ¸øÎÒÃÇÌṩÁËÓÖÒ»Ò×Óõķ½·¨¡£×¼±¸¶¯ ÊÖ°É£¡ÎÄÖÐʵÀýÓëϵͳƽ̨¾ù»ùÓÚfreebsd6.1ƽ̨¡£
Ìáʾ£º
ÔÚ½øÐÐʵ¼Ê²Ù×÷֮ǰÇëÈ·±£ÄãµÄports treeÒѾͬ²½µ½µ±Ç°°æ±¾¡£¾ßÌå·½·¨Çë²Î¿¼ÕâÀ¹ØÓÚfreebsdºÍapache2µÄ°²×°±¾ÎIJ»Óè½éÉÜ£¬Í¬Ê±¼Ù¶¨ÄãÒѾ°²×°²¢ÅäÖÃÁËËùÐè»·¾³¡£
°²×°£º
#cd /usr/ports/www/mod_cband
#make install clean
°²×°½áÊøºóĩβÊä³ö£º
chmod 755 /usr/local/libexec/apache2/mod_cband.so
[activating module `cband’ in /usr/local/etc/apache2/httpd.conf]
===> Registering installation for mod_cband-0.9.7.3
´Ëʱcband_moduleÒѾ×Ô¶¯Ìí¼Óµ½ÄãµÄhttpd.confÎļþÖв¢¿ªÆôÁË¡£
LoadModule cband_module libexec/apache2/mod_cband.so
ÖÁ´Ëmod_cband°²×°ÒѾÍê³É£¬ÈÃÎÒÃǼÌÐøºóÃæµÄ²Ù×÷¡£Ö®Ç°Ëµmod_cbandÒ×ÓÃÊÇÏà¶ÔµÄ£¬Ö÷ÒªÊÇ¿´ÄãÈçºÎÅäÖÃÈÃËûΪÄãËùÓá£Ò»Ð©»ù´¡ÅäÖû¹ÊǺÜÈÝÒ×Íê³É£¬µ«ÊÇÒª·¢»ÓËüµÄÇ¿´óºÍÁé»îÅäÖû¹ÊÇÒªºÃºÃ¿´¿´documentation£¬³ä·ÖÀí½âÁ¼ºÃ¼ÝÔ¦¡£²»†ªàÂÁË£¬ÏÂÃæ¿´¿´ÈçºÎ½øÐлù±¾ÅäÖúÍʹÓò¢¹Û²âʵ¼ÊЧ¹û¡£ÒÔÎÒÕâ¸öblogΪʵÀý£¬¿´¿´»ù±¾Çé¿ö£º
<VirtualHost *:80>
DocumentRoot “/other/blog/wordpress”
ServerName blog.citygrit.cn
<Directory “/other/blog/wordpress”>
allow from all
Options +Indexes
</Directory>
# 100MB virtualhost bandwidth limit
CBandLimit 100M
# Maximal 1024kbps speed for this virtualhost
# Maximal 10 requests per second for this virtualhost
# Maximal 30 open connections for this virtualhost
CBandSpeed 1024 10 30
# Maximal 10kB/s speed, 3 requests/s and 2 open connections for any remote client
CBandRemoteSpeed 10kb/s 3 2
# a period of time after which the scoreboard will be cleared (4 weeks)
CBandPeriod 4W
#Then you can access the status page with a URL like:http://server_name/cband-status
<Location /cband-status>
SetHandler cband-status
</Location>
#Then you can access the status page with a URL like:http://server_name/cband-status-me
<Location /cband-status-me>
SetHandler cband-status-me
</Location>
</VirtualHost>
ΪÁ˱ãÓÚÀí½â½«ÉÏÃæÄÚÈÝÀïÓëmod_cbandÏà¹ØÉèÖÃÓèÒÔ˵Ã÷£¬£¨Ô¼¶¨“#”ΪעÊͱê¼Ç£©¡£
# 100MB virtualhost bandwidth limit
CBandLimit 100M
ÏÞÖÆÐéÄâÖ÷»ú×Ü·ÃÎÊ´ø¿íΪ100Mb¡£
# Maximal 1024kbps speed for this virtualhost
# Maximal 10 requests per second for this virtualhost
# Maximal 30 open connections for this virtualhost
CBandSpeed 1024 10 30
ÏÞÖÆ´ËÐéÄâÖ÷»ú×î¸ß·ÃÎÊËÙ¶È1024kbps
ÏÞÖÆ´ËÐéÄâÖ÷»úÿÃë×î¸ß½ÓÊÜÇëÇóÊý10¸ö
ÏÞÖÆ´ËÐéÄâÖ÷»ú×î¸ß²¢·¢Á¬½Ó30¸ö
# Maximal 10kB/s speed, 3 requests/s and 2 open connections for any remote client
CBandRemoteSpeed 10kb/s 3 2
ÏÞÖÆÀ´×ÔÔ¶¶Ë·ÃÎÊËÙ¶È10kBÿÃ룬3¸öÇëÇóÿÃ룬2¸öÁ¬½Ó¡£
# a period of time after which the scoreboard will be cleared (4 weeks)
CBandPeriod 4W
É趨¶à¾Ã¶ÔËù¼Ç¼µÄÈ«¾Ö·ÃÎÊ´ø¿í½øÐÐÖØÉ裨ÇåÁ㣩¡£
4W=4 weeks 4ÖÜ£¨Ò»¸öÔ£©
#Then you can access the status page with a URL like:http://server_name/cband-status
<Location /cband-status>
SetHandler cband-status
</Location>
¿ªÆôÁËmod_cbandµÄʵʱ¼à²â¹¦ÄÜ£¬¿ÉÒÔͨ¹ýhttp://server_name/cband-status½øÐÐÖ±¹ÛµÄ¹Û²â¡££¨È«¾Ö¼à²â£©
#Then you can access the status page with a URL like:http://server_name/cband-status-me
<Location /cband-status-me>
SetHandler cband-status-me
</Location>
¿ªÆôÁËmod_cbandµÄʵʱ¼à²â¹¦ÄÜ£¬¿ÉÒÔͨ¹
![nixsky[www.nixsky.com]](/templets/images/toplogo.gif)

