在Nginx上运行fail2ban regex时了解fail2ban测试输出
我正在运行Nginx的ubuntu18.04数字海洋水滴上设置fail2ban 我随后进行了设置,并创建了一个自定义过滤器来捕获对禁止URL的请求 这是我的过滤器:在Nginx上运行fail2ban regex时了解fail2ban测试输出,nginx,fail2ban,Nginx,Fail2ban,我正在运行Nginx的ubuntu18.04数字海洋水滴上设置fail2ban 我随后进行了设置,并创建了一个自定义过滤器来捕获对禁止URL的请求 这是我的过滤器: [Definition] failregex = ^ \[error\] \d+#\d+: .* forbidden .*, client: <HOST>, .*$ ignoreregex = 下面是我正在运行的测试: /etc/fail2ban/filter.d# fail2ban-regex /var/log/n
[Definition]
failregex = ^ \[error\] \d+#\d+: .* forbidden .*, client: <HOST>, .*$
ignoreregex =
下面是我正在运行的测试:
/etc/fail2ban/filter.d# fail2ban-regex /var/log/nginx/error.log /etc/fail2ban/filter.d/nginx-forbidden.conf
以下是输出:
Running tests
=============
Use failregex filter file : nginx-forbidden, basedir: /etc/fail2ban
Use log file : /var/log/nginx/error.log
Use encoding : UTF-8
Results
=======
Failregex: 131 total
|- #) [# of hits] regular expression
| 1) [131] ^ \[error\] \d+#\d+: .* forbidden .*, client: <HOST>, .*$
`-
Ignoreregex: 0 total
Date template hits:
|- [# of hits] date format
| [200] {^LN-BEG}ExYear(?P<_sep>[-/.])Month(?P=_sep)Day(?:T| ?)24hour:Minute:Second(?:[.,]Microseconds)?(?:\s*Zone offset)?
| [254] ExYear(?P<_sep>[-/.])Month(?P=_sep)Day(?:T| ?)24hour:Minute:Second(?:[.,]Microseconds)?(?:\s*Zone offset)?
`-
Lines: 1060 lines, 0 ignored, 131 matched, 929 missed
[processed in 0.47 sec]
Missed line(s): too many to print. Use --print-all-missed to print all 929 lines
运行测试
=============
使用failregex筛选器文件:禁止使用nginx,basedir:/etc/fail2ban
使用日志文件:/var/log/nginx/error.log
使用编码:UTF-8
结果
=======
Failregex:131总计
|-#)正则表达式
|1)[131]^\[error\]\d+\d+:.*禁止。*,客户端:*$
`-
Ignoreregex:共0个
模板点击日期:
|-[#点击次数]日期格式
|[200]{^LN-BEG}ExYear(?P[-/.])月(?P=_-sep)日(?:T |?)24小时:分钟:秒(?:[,]微秒)?(?:\s*区域偏移)?
|[254]ExYear(?P[-/.])月(?P=_-sep)日(?:T |?)24小时:分钟:秒(?:[,]微秒)?(?:\s*区域偏移)?
`-
行数:1060行,忽略0行,匹配131行,遗漏929行
[处理时间为0.47秒]
缺行:太多无法打印。使用--print all missed打印所有929行
查看我的日志文件,大约有1060行,其中200行包含日期。在这200个中,131个含有“禁止”成分,所以我想可能它起作用了,但我不确定
以下是我的问题:
1) 什么是“日期模板点击”?它们是以预期格式的日期开头的行吗?因此,它们是否是应该匹配的日志条目的“候选者”
2) “忽略”和“错过”有什么区别
3) 有没有办法看到131个“匹配”的条目,这样我就可以检查它们是否像我想要捕捉的一样
4) 如果过滤器中的正则表达式显示客户机:
,那么匹配的是什么?是日志条目中的“客户端”IP地址,还是行末尾的“主机”条目
一旦你知道这些术语的含义,答案可能是显而易见的,但我找不到任何足够简单的解释来解释我的无知。太晚了,但是
ignoreregex
匹配的行(如果存在)(在您的情况下没有)。遗漏的行是那些与任何failregex
或ignoreregex
不匹配的行
--print all matched
标志
client:,
将匹配日志行中的client:xx.xx.xx,
部分
是与主机名或IP地址匹配的预定义正则表达式的别名
Running tests
=============
Use failregex filter file : nginx-forbidden, basedir: /etc/fail2ban
Use log file : /var/log/nginx/error.log
Use encoding : UTF-8
Results
=======
Failregex: 131 total
|- #) [# of hits] regular expression
| 1) [131] ^ \[error\] \d+#\d+: .* forbidden .*, client: <HOST>, .*$
`-
Ignoreregex: 0 total
Date template hits:
|- [# of hits] date format
| [200] {^LN-BEG}ExYear(?P<_sep>[-/.])Month(?P=_sep)Day(?:T| ?)24hour:Minute:Second(?:[.,]Microseconds)?(?:\s*Zone offset)?
| [254] ExYear(?P<_sep>[-/.])Month(?P=_sep)Day(?:T| ?)24hour:Minute:Second(?:[.,]Microseconds)?(?:\s*Zone offset)?
`-
Lines: 1060 lines, 0 ignored, 131 matched, 929 missed
[processed in 0.47 sec]
Missed line(s): too many to print. Use --print-all-missed to print all 929 lines