站点移至负载均衡器后,Fail2ban 正则表达式不匹配

站点移至负载均衡器后,Fail2ban 正则表达式不匹配

我安装了 fail2ban 和 nginx,它一直正常工作,直到我将其移到负载均衡器后面。因为移到负载均衡器后面后,我发现日志中显示了 2 个 IP。我希望 fail2ban 检测第一个 IP 并根据规则阻止它。以下是示例日志条目:

46.229.168.138, 64.252.86.102 - - [08/Jul/2020:10:55:08 +0530] "GET /telangana/%E0%B0%B0%E0%B0%BE%E0%B0%B7%E0%B1%8D%E0%B0%9F%E0%B1%8D%E0%B0%B0%E0%B0%82%E0%B0%B2%E0%B1%8B-%E0%B0%85%E0%B0%A6%E0%B1%8D%E0%B0%AD%E0%B1%81%E0%B0%A4%E0%B0%AE%E0%B1%88%E0%B0%A8-%E0%B0%AE%E0%B0%BE%E0%B0%B0/ HTTP/1.1" 200 18082 "-" "Amazon CloudFront"

我的 fail2ban 过滤器是:

[Definition]
failregex = <HOST> - - .*(POST|GET) .* HTTP.* 403 .*$
ignoreregex =

我的 fail2ban 监狱是:

[httpd-forbidden]
enabled = true
filter = httpd-forbidden
logpath = /var/log/nginx/example.com_custom.access.log
bantime = 1800
findtime = 300
maxretry = 50
port = 80,443
banaction = iptables-multiport

请帮助纠正 fail2ban 正则表达式。

答案1

如果第一个 IP 是需要被禁止的 IP,那么这个方法应该对你有用

[Definition]
failregex = ^<HOST>,.*"(POST|HEAD|GET|PUT).*HTTP.*" 403 .*$

相关内容