我正在使用Fail2Ban,并根据需要进行了configuration。 这是从nginx / error.log读取日志,并根据configuration关于maxretry和时间设置。 问题是这是可能有不同的规则,取决于状态代码?
例如,我想阻止任何人在5分钟内获得10 404 Status code ,但是阻止任何获得3 403 Status code 。
任何帮助将不胜感激,在此先感谢。
您应该在/etc/fail2ban/filter.d/添加一个相关名称的filter,例如nginx-{403,404}.conf 。
它们应该包含如下所示的内容:
nginx-403.conf:
[Definition] failregex = ^<HOST> -.*"(GET|POST|HEAD).*HTTP.*" 403 ignoreregex =
nginx-404.conf:
[Definition] failregex = ^<HOST> -.*"(GET|POST|HEAD).*HTTP.*" 404 ignoreregex =
那么你应该从你的jail.conf或者你的conf文件中调用它们:
对于403:
[nginx-403] enabled = true port = http,https filter = nginx-403 logpath = /var/log/nginx/access.log maxretry = 5 findtime = 300
而对于404:
[nginx-404] enabled = true port = http,https filter = nginx-404 logpath = /var/log/nginx/access.log maxretry = 10 findtime = 300