参考:https://blog.csdn.net/dorisnzy/article/details/82926067
1、安装fail2ban:
yum -y install epel-release
yum -y install fail2ban
2、配置fail2ban:
修改/etc/fail2ban/jail.conf
[default]
destemail = [email protected]
sender = Nginx[email protected]
#这里需要修改发送和接收邮件的邮箱
[Nginx]
enabled = true
port = http,https
filter = Nginx
action = iptables[name=Nginx, port=http, protocol=tcp]
action = %(mta)s-whois[name=%(__name__)s, sender="%(sender)s", dest="%(destemail)s", protocol="%(protocol)s", chain="%(chain)s"]
#这里增加了邮件通知
logpath = /var/log/Nginx/access.log
bantime = 3600
findtime = 60
maxretry = 5
增加/etc/fail2ban/filter.d/Nginx.conf
[DeFinition]
failregex = <HOST> -.*- .*HTTP/1.* 404 .*$
ignoreregex = <HOST> -.*- .*GET /www/common/.*$
#ignoreregex是忽略的地址,防止因页面代码写的不好引发的错判,如果不需要可以留空
修改/etc/postfix/mail.cf
主要是修改releyhost = 10.0.30.1
本身有内部邮件的smtp转发服务器
3、检查fail2ban规则
fail2ban-regex /var/log/Nginx/access.log /etc/fail2ban/filter.d/Nginx.conf /etc/fail2ban/filter.d/Nginx.conf --print-all-match --print-all-ignore
注意:上面有2次用到/etc/fail2ban/filter.d/Nginx.conf,是因为我配置了ignoreregex的内容
4、启动fail2ban和postfix
service postfix restart
service fail2ban restart
5、检查fail2ban
fail2ban-client status
fail2ban-client status ngixn-get-dos
分别检查的是fail2ban的总开关状态,和其中Nginx-get-dos功能的扫描状态
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。