Original module: http://dominia.org/djao/limitipconn2.html
Compiled by ntropic for the Windows 32 platform running Apache 2.2.11: http://ntropic.org/files/mod_limitipconn.httpd-2.2.11-WIN32.zip
Compiled with apache 2.2.11 with Visual C++ 2005 Express GUI. May work on other apache versions too? If not, see Original module.
FOR THIS MODULE YOU NEED:
1. X32 COMPATIBLE OS [2000/NT/XP/2003/VISTA/2008] (Note: Only partially tested on Windows XP SP3 and Windows 2003 Server R2 SP2 Enterprise Ed.)
2. X32 COMPILED APACHE HTTPD AND MODULES
*if you dont know how to use this module, check the original readme at here: http://dominia.org/djao/limitipconn2.html
This is an EXPERIMENTAL BUILD ONLY! USE AT YOUR OWN RISK! (Especially for 2000/VISTA/2008)
Please do not ask me questions on how it was compiled or support on it's use. Like sawo, I am not quite sure how I
successed in compiling the .dll - I'm not a programmer/coder. It just happened. Now, if I could only be so lucky at the Lottery.
See the original documentation at http://dominia.org/djao/limitipconn2-README for use, configuration and notes.
I prefer not to receive emails as I compliled this for myself as the pre-existing precompiled build for Win32 would not
load under httpd-2.2.11, however, if you must you try to contact me you can email me at ntropic [at] ntropic.org. Don't be offended
if I do not reply - I am a busy person.
Thanks and Credits to:
Apachez (Precompiled Win32 DLL and VC2005 Project files)
Ben (Compilation Environment)
David Jao (Original Creator)
sawo (see http://www.apachelounge.com/viewtopic.php?p=12682#12682) for inspiration.
## Basic Use (copied from Ben's Readme):
---------------------------------------------------------------------------
#Make sure mod_status is loaded
ExtendedStatus On
# Only needed if the module is compiled as a DSO
LoadModule limitipconn_module modules/mod_limitipconn.dll
<IfModule mod_limitipconn.c>
<Location /somewhere>
MaxConnPerIP 3
# exempting images from the connection limit is often a good
# idea if your web page has lots of inline images, since these
# pages often generate a flurry of concurrent image requests
NoIPLimit image/*
</Location>
<Location /mp3>
MaxConnPerIP 1
# In this case, all MIME types other than audio/mpeg and video*
# are exempt from the limit check
OnlyIPLimit audio/mpeg video
</Location>
</IfModule>
---------------------------------------------------------------------------
Please refer to README.David for original manual, and visit
http://dominia.org/djao/limitipconn.html for more info about this module.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
修改配置文件:
1全局控制:
在httpd.conf加上以下几行:
< IfModule mod_limitipconn.c >
< Location / > # 所有虚拟主机的/目录
MaxConnPerIP 3 # 每IP只允许3个并发连接
NoIPLimit image/* # 对图片不做IP限制
< /Location >
< Location /mp3 > # 所有主机的/mp3目录
MaxConnPerIP 1 # 每IP只允许一个连接请求
OnlyIPLimit audio/mpeg video # 该限制只对视频和音频格式的文件
< /Location >
< /IfModule >
2 局部限制,你也可以在虚拟主机的配置文件里设置IP限制,方法是完全?谎?:
< VirtualHost xx.xxx.xx.xx >
ServerAdmin chenlf@chinalinuxpub.com
DocumentRoot /home/my
ServerName www.my.com
< IfModule mod_limitipconn.c >
< Location / > # 所有虚拟主机的/目录
MaxConnPerIP 5 # 每IP只允许3个并发连接
NoIPLimit image/* # 对图片不做IP限制
< /Location >
< Location /mp3 > # 所有主机的/mp3目录
MaxConnPerIP 2 # 每IP只允许一个连接请求
OnlyIPLimit audio/mpeg video # 该限制只对视频和音频格式的文件
< /Location >
< /IfModule >
ErrorLog /home/my/logs/error_log
CustomLog /home/my/logs/access_log common
< /VirtualHost >
3 此外必须将apache的ExtendedStatus设置为ON.在httpd.conf找到
# ExtendedStatus On
去掉前面的注释即可
好了,全部配置结束,重起apache就可以生效了
apache2.2.8 使用 mod_limitipconn 限制用户下载使用线程数目
2009-05-14 分类:Linux 标签: apache 作者:fanzg
网站如果提供一些文件下载,最头疼问题,可能就是用户使用多线程下载,
这样很快耗尽服务器资源,特别是对于一些小网站,许多线程同时访问请求,
一定会对服务器造成一定得影响。
这里我演示一个 可以 限制下载使用的线程数目,只适合于apache服务器,呵呵。
首先测试一下,一个test.avi 如果在服务器被下载的情况,在没有使用限制ip并发连接数,
也就是使用下载工具没有限制线程数量。
我现在服务器上有一个 test.avi 文件,再没有任何限制之下,我们使用迅雷下载
并且设置 5 个线程进行下载。看到了吧, 5个线程都正常请求,在同时下载文件。
好,我先把下载文件 暂停了,
下面我们来安装 限制下载使用的线程(也就是限制同一个ip并发数量)
我这里使用 apache 2.2.8版本
1. 先下载 mod-limitipconn
在http://dominia.org/djao/limitipconn2.html上下载对应的版本,我下载的是for apache 2.2的版本(mod-limitipconn-0.23.tar.bz2)。
下载方面,我也会在文章最后提供下载,我现在把它传进Linux下。
2. 安装
# tar xjvf mod_limitipconn-0.23.tar.bz2
mod_limitipconn-0.23/
mod_limitipconn-0.23/Makefile
mod_limitipconn-0.23/mod_limitipconn.c
mod_limitipconn-0.23/README
mod_limitipconn-0.23/ChangeLog
mod_limitipconn-0.23/INSTALL
mod_limitipconn-0.23/LICENSE
# cd mod_limitipconn-0.23
这里注意路径,也就是你自己apache安装的路径。
# /usr/local/apache2/bin/apxs -c -i -a mod_limitipconn.c
该步骤会自动将mod_limitipconn.so编译到apache对应的modules目录中,
还会在httpd.conf文件中自动添加loadmodules语句
最后 修改httpd.conf
vi /etc/httpd.conf
我把下面的修改信息 添加到配置文件最后面。
ExtendedStatus On
<IfModule limitipconn_module>
<Location />
MaxConnPerIP 3
NoIPLimit image/*
</Location>
<Location /mp3>
MaxConnPerIP 1
OnlyIPLimit audio/mpeg video
</Location>
</IfModule>
最后保存退出。
重启apache
[root@localhost /]# /usr/local/apache2/bin/apachectl stop
[root@localhost /]# /usr/local/apache2/bin/apachectl start
接着再使用迅雷继续下载刚才的视频文件,观察线程链接情况。
可以看到 5个线程中,有2个线程是不能读取数据的,只有3个线程可以进行连接读取数据。
MaxConnPerIP 3 这个就是配置文件中 所限制的 ip并发连接数目,也就是
我们进行下载允许的线程连接数目。好了,演示就到这里,谢谢大家观看。