最後更新: 2015-04-16
介紹
Homepage: http://bwmod.sf.net
支援 mpm, prefork
用圖
* restrict the top speed a site is able to use
* restrict the max connections allowed per site
Install
mod_bw 可以在 epel repos download 到
yum install mod_bw
安裝後有以下 file
- /usr/lib/httpd/modules/mod_bw.so
- /etc/httpd/conf.d/mod_bw.conf
原理
1. set a shared memory holding all of the configuration
2. keep a "count" of the info currently using (shared memory)
3. the mod will "split" the data, and will send it piece by piece (delay between pieces)
設定
/etc/httpd/conf.d/mod_bw.conf
# mod_bw 不支援 Global setting 的, 所以這 file 不用放設定
LoadModule bw_module modules/mod_bw.so
Per vhost setting
<VirtualHost *> # 啟用此 module, Default Off BandWidthModule On # On => The mod will catch every request.(Default: Off) #ForceBandWidthModule Off #AddOutputFilterByType BW_MOD text/html text/plain # 由於唔想煩, 所以直接 On 了它 (P.S. 放在 Global 係無效的) ForceBandWidthModule On # BandWidth [From] [bytes/s] # From: 192.168.0.0/24 or all # First entries("From") have precedence # 0 => no limit. BandWidth all 102400000 # MaxConnection [From] [Max] # *** You NEED to have a BandWidth limit for the same origin. # (It's because im using them same memory space) MaxConnection all 20 # value>0 每個 client 會平分 "BandWidth", 當不夠分時都保證最少有 value # value=0 => 當不夠分時, 會用 default valuse (256 bytes/s) # value=-1 => 每個 client fix 死有 "BandWidth" MinBandWidth all 50000 # At default, when "MaxConnection" is reached, the mod will issue a 503(Service Temporarily Unavailable) BandWidthError 510 ErrorDocument 510 /Path/To/ErrDoc.html <Directory /home/vhosts/mywebsite/web> # LargeFileLimit [Type] [Minimum Size(kbyte)] [bytes/s] # Type = * to match all # This limits .avi files over (or equal to) 500kb to 10kbytes/s # LargeFileLimit .avi 500 10240 LargeFileLimit * 1024 102400 </Directory> </VirtualHost>
mini configure
BandwidthModule On ForceBandWidthModule On Bandwidth all 102400 MinBandwidth all 40960 MaxConnection all 3 BandWidthError 510 ErrorDocument 510 "Your website over connection limit. Please contact server admin."
DOC
http://bwmod.sourceforge.net/files/mod_bw-0.7.txt
Other
- mod_bandwidth
- mod_cband