星哥的博客

  • 首页
  • 系统
  • 虚拟机
  • 网站开发
  • 硬件外设
  • VPS/云主机
  • 心情随笔
  1. 首页
  2. 网站开发
  3. Apache
  4. 正文

bw_moudle模块设置apache限速

2011年8月11日 2514点热度 0人点赞 0条评论

因需要,现对一个xampp环境apache用户连接实行限速设置。所需使用外部模块”mod_bw”。实施及相关说明如下:


1、下载mod_bw最新0.92版

[root@xmydlinux ~]#wget -c http://ivn.cl/files/source/mod_bw-0.92.tgz

2、安装mod_bw到xampp环境中

[root@xmydlinux ~]#mkdir -p mod_bw
[root@xmydlinux ~]#tar zxvf mod_bw-0.92.tgz -C mod_bw
ChangeLog
LICENSE
mod_bw.c
mod_bw.txt
TODO
[root@xmydlinux ~]#cd mod_bw

安装该模块的时候如果提示报错,如下:

[root@xmydlinux ~]#/opt/lampp/bin/apxs -i -a -c mod_bw.c
cannot open /opt/lampp/build/config_vars.mk: No such file or directory at /opt/lampp/bin/apxs line 218.

则需下载安装xampp的开发套件 “xampp-devel”

[root@xmydlinux ~]#wget -c http://sourceforge.net/projects/xampp/files/XAMPP%20Linux/1.7.3a/xampp-linux-devel-1.7.3a.tar.gz/download
[root@xmydlinux ~]#tar xvfz xampp-linux-devel-1.7.3a.tar.gz -C /opt

再次安装则可正常安装成功。

[root@xmydlinux ~]#/opt/lampp/bin/apxs -i -a -c mod_bw.c
[root@gdsaas ~]# ll /opt/lampp/modules/ |grep mod_bw
-rwxr-xr-x 1 root root 22263 12-18 11:15 mod_bw.so
[root@gdsaas ~]# grep mod_bw.so /opt/lampp/etc/httpd.conf
LoadModule bw_module modules/mod_bw.so

根据上面查看,模块已经安装成功。。
3、模块使用方法,请查看解压目录中”mod_bw.txt”,因为本文中所使用为在虚拟主机中实现控制,固引用该部分说明文档如下:

- Examples
1 - Misc examples Limit every user to a max of 10Kb/s on a vhost :

<Virtualhost *>
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 10240
MinBandwidth all -1
Servername www.example.com
</Virtualhost>

Limit al internal users (lan) to 1000 kb/s with a minimum of 50kb/s , and
files greater than 500kb to 50kb/s.

<Virtualhost *>
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 1024000
MinBandwidth all 50000
LargeFileLimit * 500 50000
Servername www.example.com
</Virtualhost>

Limit avi and mpg extensions to 20kb/s.

<Virtualhost *>
BandwidthModule On
ForceBandWidthModule On
LargeFileLimit .avi 1 20000
LargeFileLimit .mpg 1 20000
Servername www.example.com
</Virtualhost>

Using it the "right" way, with output filter by mime type (for text)
to 5kb/s:

<Virtualhost *>
BandwidthModule On
AddOutputFilterByType MOD_BW text/html text/plain
Bandwidth all 5000
Servername www.example.com
</Virtualhost>

4、设置虚拟主机现在客户端最大连接数为1,限制速度为10K。并验证
虚拟主机配置文件如下:

<virtualHost *>
DocumentRoot /opt/lampp/htdocs/webroot
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 10240
MinBandwidth all -1
MaxConnection all 1
ServerName www.test.cn
 </VirtualHost>

由于我们给用户设置最大连接数为1,在下载的时候我们打开网站,可以看到下面提示

Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
这个是模块默认的达到连接上限的503错误页面。。我们可以根据实际情况更改。根据以上配置及测试,可以说明我们的mod_bw模块限速是正常工作的。。
那么接下来就可以根据自己的实际情况及带宽设置相应的最大连接数以及上限速度了。。

标签: 暂无
最后更新:2011年8月11日

wangxingcs

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

This site uses Akismet to reduce spam. Learn how your comment data is processed.

wangxingcs

这个人很懒,什么都没留下

我的博客

仅记录一些有用的教程,自己的经历,已屏蔽各大搜索引擎收录。

新浪微博 @wangxingcs

Twitter @wangxingcs(常在)

最新 热点 随机
最新 热点 随机
Proxmox VE(PVE)6.X 添加硬盘 PVE解决VM is locked问题 Proxmox VE配置更新源 黑群晖显示真实CPU信息(支持7.0.1) Proxmox VE直通硬盘(全盘映射方式) PVE去除“没有有效订阅”提示
ecshop添加注册短信验证功能 入手PlayBook F660破解时遇到 当前操作无效 的解决方法 CentOS下安装PPTP VPN小记 Hyper-V 安装 Linux Integration Services v2.1 AMH5下给NGINX开启SPDY支持
标签聚合
MTP 驱动 PVE 虚拟机 群晖 CMS DSM FineCMS

COPYRIGHT © 2015-2023 wangxingcs.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

陕ICP备13007295号