如何使用Apache中的Mod安全模块对每个网站进行速率限制?

问题描述 投票:0回答:1

我已经在 Ubuntu 22.04 上为 Apache 2.4.52 版本设置了 Mod Security (v2.9.5)。

我想使用 Mod 安全规则对每个网站进行“速率限制”,它应该要求客户端在“n”次(可能是秒)后重试。

所以我的 Apache 服务器运行 100 多个网站,我需要为每个网站设置不同的速率限制。 喜欢

  • domain1.com - 来自同一 IP 的 100 个请求/分钟
  • domain2.com - 来自同一 IP 的 100 个请求/分钟

我正在尝试为此设置规则,但我认为我需要更多使用 mod 安全性的专业知识来构建这样的规则。

# Rule 1: Initialize website-specific counter
SecAction "phase:1,id:900,pass,initcol:ip=%{REMOTE_ADDR}/%{SERVER_NAME}/count/60"

# Rule 2: Increment website-specific counter and log full variable
SecRule REQUEST_HEADERS:Host "@rx ^([^:]+)" \
  "id:901,log,pass,setvar:ip.%{REMOTE_ADDR}/%{SERVER_NAME}/count/60+=1"
# Rule 3: Block if request count exceeds 100 per 60 seconds
SecRule IP:%{REMOTE_ADDR}/%{SERVER_NAME}/count/60 "@gt 1" \
    "id:902,phase:1,deny,status:429,\
    log,msg:'Client exceeded request limit for %{SERVER_NAME} from IP %{REMOTE_ADDR}, please try again later.'"

有人可以帮我吗?

apache rate-limiting mod-security
1个回答
0
投票

您可能需要使用 Apache mod-evasive 之类的东西来实现此目的。我提供您正在寻找的所需功能。

© www.soinside.com 2019 - 2024. All rights reserved.