Fail2Ban 阻塞行为取决于状态代码

Par*_*met 9 security nginx fail2ban

我正在使用 Fail2Ban 并根据需要对其进行了配置。这是从 nginx/error.log 读取日志,并根据有关 maxretry 和计时集的配置进行操作。问题是这是否可能根据状态代码有不同的规则?

例如,我想阻止任何人404 Status code在 5 分钟内获得 10 ,但阻止任何人获得 3 403 Status code

任何帮助将不胜感激,提前致谢。

小智 16

您应该添加一个/etc/fail2ban/filter.d/具有相关名称的过滤器- 例如nginx-{403,404}.conf

它们应该包含类似于以下几行的内容:

nginx-403.conf :

[Definition]
failregex = ^<HOST> -.*"(GET|POST|HEAD).*HTTP.*" 403
ignoreregex =
Run Code Online (Sandbox Code Playgroud)

nginx-404.conf :

[Definition]
failregex = ^<HOST> -.*"(GET|POST|HEAD).*HTTP.*" 404
ignoreregex =
Run Code Online (Sandbox Code Playgroud)

然后你应该从你的 jail.conf 或任何你的 conf 文件中调用它们:

对于 403 :

[nginx-403]

enabled = true
port    = http,https
filter  = nginx-403
logpath = /var/log/nginx/access.log
maxretry = 5
findtime = 300
Run Code Online (Sandbox Code Playgroud)

而对于 404 :

[nginx-404]

enabled = true
port    = http,https
filter  = nginx-404
logpath = /var/log/nginx/access.log
maxretry = 10
findtime = 300
Run Code Online (Sandbox Code Playgroud)

  • 监狱文件中不再需要“过滤器”行 - 请参阅优化 fail2ban 过滤器 http://www.the-art-of-web.com/system/fail2ban-filters/ (2认同)
  • 它是如何禁止的? (2认同)
  • @chovy 引用前一个评论者链接的那个网页,“在 Fail2Ban 0.9.x 中,方括号中的监狱标题也标识了正在使用的过滤器。” (2认同)