nginx下使用fail2ban防止網站被CC

來源:互聯網
上載者:User

標籤:ant   script   log   cti   tab   檔案   table   lte   pat   

--安裝fail2ban
yum install -y epel-release
yum install -y fail2ban


--配置fail2ban
vi /etc/fail2ban/jail.conf
[http-get-dos]
enabled = true
port = http
filter = http-get-dos
logpath = /home/wwwlogs/access.log
maxretry = 100
findtime = 5
bantime = 600
action = iptables[name=HTTP,port=http,protocol=tcp]

/* 參數含義
filter = http-get-dos #--filter.d/http-get-dos.conf 檔案名稱
logpath = /home/wwwlogs/access.log #--需要監控nginx日誌log
maxretry = 100 #-- 最多訪問100
findtime = 10 #-- 10秒
bantime = 1200 #-- 20分鐘
*/

vi /etc/fail2ban/filter.d/http-get-dos.conf
[Definition]
failregex = <HOST> -.*- .*HTTP/1.* .* .*$
ignoreregex =


--配置fail2ban日誌
vi /etc/fail2ban/fail2ban.conf
loglevel = WARNING
logtarget = /var/log/fail2ban.log

 

--重啟生效
service fail2ban restart


--屏蔽日誌
tail -f /var/log/fail2ban.log


--#刪除屏蔽
iptables -D f2b-HTTP 1

 

 

--定時清理 nginx / fail2ban 日誌

vi /root/scripts/del_cc_log.sh
#! /bin/bash

cat /dev/null > /home/wwwlogs/access.log
cat /dev/null > /var/log/fail2ban.log

 

crontab -e
30 3 * * 0 sh /root/scripts/del_cc_log.sh


--開啟crontab
/etc/init.d/crond start

chkconfig --list|grep crond

 

 

--屏蔽ssh探測
vi /etc/fail2ban/jail.conf

[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp]
logpath = /var/log/secure
maxretry = 10
bantime = 144000

 


--#刪除屏蔽
iptables -D f2b-SSH 1

nginx下使用fail2ban防止網站被CC

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.