为Apache安装Mod_limitipconn连接数限制模块

By | 2014年7月18日

在Apache 2.2 2.4版本中,使用这个限速模块,在这个地址下载源码包:http://dominia.org/djao/limitipconn2.html 

安装说明: 

Instructions for statically compiling mod_limitipconn into httpd:

tar xavf httpd-2.4.2.tar.bz2
tar xavf mod_limitipconn-0.24.tar.bz2
cd httpd-2.4.2
./configure --with-module=aaa:../mod_limitipconn-0.24/mod_limitipconn.c
make
make install

Instructions for building as a Dynamic Shared Object (DSO):

tar xavf mod_limitipconn-0.24.tar.bz2
cd mod_limitipconn-0.24
make install

配置说明:

# This command is always needed
ExtendedStatus On

# Only needed if the module is compiled as a DSO
LoadModule limitipconn_module lib/apache/mod_limitipconn.so

<IfModule mod_limitipconn.c>

    # Set a server-wide limit of 10 simultaneous downloads per IP,
    # no matter what.
    MaxConnPerIP 10
    <Location /somewhere>
	# This section affects all files under http://your.server/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>

    <Directory /home/*/public_html>
	# This section affects all files under /home/*/public_html
	MaxConnPerIP 1
	# In this case, all MIME types other than audio/mpeg and video*
	# are exempt from the limit check
	OnlyIPLimit audio/mpeg video
    </Directory>
</IfModule>

超过连接数后,返回503错误,可以自定义一个503页面,来友好显示原因。

定义503页面,需要在httpd.conf配置中写入:

ErrorDocument 503 /errhtml/503.html

在网站根目录,errhtml目录中放入503页面即可。