I’ve been experimenting on how I can limit the download speed via Apache configuration. This method is good for file-sharing website and for hosting servers. In my case, I am using Centos 5.5 and Apache 2.2.3 + mod_cband 0.9.7.5.So, here’s what you will do… Assume you already installed the Apache.Install Apache Development libraries by casting “yum -y install apache-devel”Download “mod_cband” from
http://dembol.org/blog/mod_cband/ or direct download link at
http://dembol.org/downloads/cband/mod-cband-0.9.7.5.tgzFollow steps (must be root mode)…cd ~wget http://dembol.org/downloads/cband/mod-cband-0.9.7.5.tgztar xzvf mod-cband-0.9.7.5.tgzcd mod-cband-0.9.7.5./configuremakemake installTo check if successfully installed, type just like below and must have same result:[root@localhost ~]# cat /etc/httpd/conf/httpd.conf | grep mod_cband.soLoadModule cband_module /usr/lib/httpd/modules/mod_cband.soThen add the code below at httpd.conf then save and restart apache.CBandScoreFlushPeriod 1CBandRandomPulse OnNext is add a “scoreboard”mkdir /var/www/scoreboardchown apache:apache /var/www/scoreboard/Final steps is create an vhost entry at /etc/httpd/conf.d just like this (in my case, I created cband.com as my vhost);[root@localhost conf.d]# cat cband.com.conf<VirtualHost *:80> ServerAdmin
webmaster@cband.com DocumentRoot /home/cband.com/public_html ServerName cband.com CBandSpeed 1024 10 30 CBandRemoteSpeed 50kb/s 3 3 CBandLimit 500M CBandExceededSpeed 128 5 15 CBandScoreboard /var/www/scoreboard CBandPeriod 4W CBandExceededURL http://cband.com/exceeded.html <Location /cband-status> SetHandler cband-status </Location> <Location /cband-status-me> SetHandler cband-status-me </Location> ErrorLog logs/cband.com-error_log CustomLog logs/cband.com-access_log common</VirtualHost>[root@localhost conf.d]#After you created the vhost file, restart your apache.You can check the status of certain vhost by accessing the URL:
http://cband.com/cband-statusor another status URL:
http://cband.com/cband-status-meFurther Explanation:CBandSpeed 1024 10 30 — Overall apache performance. Max bandwidth speed is 1024bits per secs. 10 requests per secs. 30 max connectionsCBandRemoteSpeed 50kb/s 3 3 — Individual apache performance. Max bandwidth speed is 50kb/s, max 3 requests/s and max 3 connectionsCBandLimit 500M — 500MB max bandwidth limitCBandExceededSpeed 128 5 15 — Bandwidth speed limit at 128kbps, 5 request/s and max of 15 connectionsCBandScoreboard /var/www/scoreboard — scoreboard locationCBandPeriod 4W – time to refreshCBandExceededURL
http://cband.com/exceeded.html — if bandwidth exceeded, redirect to the specified URL.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.Reference:
http://www.howtoforge.com/mod_cband_apache2_bandwidth_quota_throttlingDownload mod_cband file:mod_cband v0.9.5 (141)
http://dembol.org/downloads/cband/mod-cband-0.9.7.5.tgz