|
本帖最后由 不长叶子的树 于 2024-8-17 00:45 编辑
建议使用mod_reqtimeout和mod_qos两个模块相互配合来防护HTTP慢攻击(Slow HTTP Attack)
1、mod_reqtimeout用于控制每个连接上请求发送的速率。
#请求头部分,设置超时时间初始为10秒,并在收到客户端发送的数据后,每接收到500字节数据就将超时时间延长1秒,但最长不超过40秒。可以防护slowloris型的慢速攻击。
RequestReadTimeout header=10-40,minrate=500
#请求正文部分,设置超时时间初始为10秒,并在收到客户端发送的数据后,每接收到500字节数据就将超时时间延长1秒,但最长不超过40秒。可以防护slow message body型的慢速攻击。
RequestReadTimeout body=10-40,minrate=500
需注意,对于HTTPS站点,需要把初始超时时间上调,比如调整到20秒。
示例:- # 加载reqtimeout模块
- LoadModule reqtimeout_module modules
- <IfModule reqtimeout_module>
- RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500
- </IfModule>
复制代码
2、mod_qos 是一个Apache HTTP服务器的模块,用于限制连接/控制并发连接数和请求的速率。
配置例如:
#当服务器并发连接数超过600时,关闭keepalive
QS_SrvMaxConnClose 600
#限制每个源IP最大并发连接数为50
QS_SrvMaxConnPerIP 50
这两个数值可以根据服务器的性能调整。
示例:
先下载附件的mod_qos.so模块到Apache 2.4目录下
- # 加载mod_qos模块
- LoadModule qos_module modules/mod_qos.so
- <IfModule qos_module>
- # handle connections from up to 100000 different IPs
- #QS_ClientEntries 100000
- # allow only 50 connections per IP;限制每个源IP最大并发连接数为20
- QS_SrvMaxConnPerIP 20
- # limit maximum number of active TCP connections limited to 256
- #MaxClients 640
- # disables keep-alive when 180 (70%) TCP connections are occupied
- QS_SrvMaxConnClose 70%
- # enables the known client prefer mode (server allows new TCP connections
- # from known/good clients only if there are more than 716 open TCP connections):
- QS_ClientPrefer 80%
- # minimum request/response speed
- # (deny slow clients blocking the server, keeping connections open without requesting anything
- QS_SrvMinDataRate 64 512 200
- # disables connection restrictions for certain clients (trusted proxy servers);排除的IP地址
- QS_SrvMaxConnExcludeIP 192.168.1.123
- QS_SrvMaxConnExcludeIP 123.123.123.123
- </IfModule>
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|