哪些技术和/或模块可用于在apache中实现强健的速率限制(请求|字节/ ip /单位时间)?如何使用Apache实现速率限制? (每秒请求数)
66
A
回答
48
5
在Apache的2.4,有一个名为mod_ratelimit有新货模块。为了模拟调制解调器的速度,你可以使用mod_dialup。虽然我不明白为什么你不能使用mod_ratelimit做任何事情。
1
15
正如this blog后说,它似乎可以使用Apache的mod_security实现每秒的速度极限。
的配置是这样的:
SecRuleEngine On
<LocationMatch "^/somepath">
SecAction initcol:ip=%{REMOTE_ADDR},pass,nolog
SecAction "phase:5,deprecatevar:ip.somepathcounter=1/1,pass,nolog"
SecRule IP:SOMEPATHCOUNTER "@gt 60" "phase:2,pause:300,deny,status:509,setenv:RATELIMITED,skip:1,nolog"
SecAction "phase:2,pass,setvar:ip.somepathcounter=+1,nolog"
Header always set Retry-After "10" env=RATELIMITED
</LocationMatch>
ErrorDocument 509 "Rate Limit Exceeded"
5
可悲的是,mod_evasive
将不会工作在非prefork的配置中使用时,如预期(近期的Apache设置主要是MPM)
9
有许多方式包括Web应用程序防火墙,但是如果使用Apache mod最容易实现。
我喜欢推荐的一个这样的mod是mod_qos。这是一个免费的模块,对于certin DOS,Bruteforce和Slowloris类型的攻击非常有效。这会缓解你的服务器负载。
这是非常强大的。
的mod_qos模块的当前版本实现控制机制来管理:
并发请求到位置/资源 (URL)或虚拟主机的最大数量。
限制带宽,如每秒对URL的最大允许请求数或者每秒下载的千字节数的最大值/最小值。
限制每秒请求事件(特殊请求 条件)的数量。
- 限制请求事件在定义的时间段内的数量。
- 它还可以检测到非常重要的人员(VIP),这些人员可能访问 Web服务器时没有或有较少的限制。
通用请求线和头滤波器来拒绝未授权的 操作。
请求正文数据限制和过滤(要求mod_parp)。
限制为单个客户端(IP)请求事件的数量。
限制在TCP连接的水平,例如,从单一的IP源地址或动态 保活控制 允许的连接的最大数量。当服务器运行了免费的TCP连接 的
- 喜欢称为IP地址。
这是什么,你可以使用它的一个示例配置。有数百种可能的配置可以满足您的需求。访问该网站获取更多关于控件的信息。
Sample configuration:
# minimum request rate (bytes/sec at request reading):
QS_SrvRequestRate 120
# limits the connections for this virtual host:
QS_SrvMaxConn 800
# allows keep-alive support till the server reaches 600 connections:
QS_SrvMaxConnClose 600
# allows max 50 connections from a single ip address:
QS_SrvMaxConnPerIP 50
# disables connection restrictions for certain clients:
QS_SrvMaxConnExcludeIP 172.18.3.32
QS_SrvMaxConnExcludeIP 192.168.10.
我使用Linux的[TC](http://www.lartc.org/howto/lartc.qdisc.classless.html#AEN690)在Web服务器上,因为红帽6只有Apache 2.2。 – ceving 2014-05-19 12:17:18