Fail2Ban:RegEx 用于从 Apache 日志中过滤掉所有 404 错误

Fail2Ban:RegEx 用于从 Apache 日志中过滤掉所有 404 错误

在我的日志中,我经常看到大量的 404 错误,其中机器人显然会系统地扫描服务器以查找特定软件安装。由于这也会造成大量流量,所以我想禁止它们。

因此,根据一些 HowTos,我尝试为 fail2ban 找到一个 RegEx,它可以从 Apache 日志中过滤掉这些 404 请求,并在此基础上阻止相关的 IP。

不幸的是,我找到并尝试的所有 RegEx 模式都不起作用。例如:

fail2ban-regex /var/log/apache2/other*access.log '^<HOST> - .* "(GET|POST|HEAD).*HTTP.*" 404 .*$'

(对我来说看起来不错)没有找到任何东西:

Date template hits:
|- [# of hits] date format
|  [1210] Day(?P<_sep>[-/])MON(?P=_sep)ExYear[ :]?24hour:Minute:Second(?:\.Microseconds)?(?: Zone offset)?
`-

Lines: 1210 lines, 0 ignored, 0 matched, 1210 missed

该日志文件中肯定有几个 404 错误。那么我做错了什么?正确的 RegEx 应该如何获取所有 404?

谢谢!

答案1

other_vhosts_access.log默认情况下,与标准相比,LogFormat vhost_combined它有一个不同的前缀。您需要相应地修改正则表达式。vhost:portcommon LogFormat

答案2

你试过这个吗

failregex = ^<HOST> - .* "(GET|POST|HEAD).*HTTP.*" 404 .*$
ignoreregex =.*(robots.txt|favicon.ico|jpg|png)

相关内容