限制访问带宽
Bandwidth Mod
http://ivn.cl/category/apache/
sudo apxs -c -i -a mod_bw.c
若没有apxs, 则需安装 apache2-dev
代码如下
listen 10004
NameVirtualHost *:10004
<VirtualHost *:10004>
DocumentRoot "/home/zhangy/www/test"
ServerName *:10004
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 1024000
MinBandwidth all 50000
LargeFileLimit * 500 50000
MaxConnection all 6
ErrorLog "/home/zhangy/apache/www.test.com-error.log"
CustomLog "/home/zhangy/apache/www.test.com-error.log" common
</VirtualHost>
解压bandwidth的压缩文件后,里面有一个mod_bw.txt有详细的说明和实例,下面是部分参数说明:
1,BandWidth localhost 0 #对localhost不限速
2,BandWidth 192.168.1.5 102400 #对192.168.1.5限速为100KB
3,BandWidth “u:^Mozilla(.*)” 10240 #用mozilla时限速10KB
4,BandWidth “u:wget” 102400 #如果用wget下载时限速10KB
5,MinBandWidth all -1 #保证每个客户端最高速度可达10KB
6,LargeFileLimit .jpg 100 10240 #jpg文件超过100KB,限速10KB
7,#下面的510挺好,如果不设置,apache自己会报错,就根报404差不多,页面非常的丑
ErrorDocument 510 /exceed_speed.html
BandWidthError 510
8,MaxConnection all 10 #所有ip最大连接数为10
9,MaxConnection 192.168.1.5 5 #192.168.1.5最大连接数为5