Nginx+iptables屏蔽访问Web页面过于频繁的IP(防DDOS,恶意访问,采集器)
警犬巴打国语版,齐齐哈尔交通违章查询,斗战神清水洞
脚本如下:
#!/bin/sh
nginx_home = /data/app_1/nginx
log_path = /data/logs
/usr/bin/tail -n50000 $log_path/access.log \
|awk ‘$8 ~/aspx/{print $2,$13}' \
|grep -i -v -e “google|yahoo|baidu|msnbot|feedsky|sogou” \
|awk ‘{print $1}'|sort|uniq -c |sort -rn \
|awk ‘{if($1>150)print “deny “$2″;”}'> $nginx_home/conf/vhosts/blockip.conf
/bin/kill -hup `cat $nginx_home/nginx.pid`
也可以通过分析nginx日志过滤出频繁访问ip,直接用iptables屏蔽这个ip,就用不着重启nginx了,并且屏蔽效果更好。
单个ip的命令是
iptables -i input -s 124.115.0.199 -j drop
封ip段的命令是
iptables -i input -s 124.115.0.0/16 -j drop
封整个段的命令是
iptables -i input -s 194.42.0.0/8 -j drop
封几个段的命令是
iptables -i input -s 61.37.80.0/24 -j drop
iptables -i input -s 61.37.81.0/24 -j drop
刚才不小心搞的自己都连不上了-_-!!!
iptables -i input -p tcp –dport 80 -s 124.115.0.0/24 -j drop
以后用这种只封80端口就行了,不会出问题!
iptables -i input -p tcp –dport 80 -s 124.115.0.0/24 -j drop
iptables -i input -s 61.37.81.0/24 -j drop
解封
iptables -f
清空
iptables -d input 数字
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
-
-
-
nginx实现动静分离实例讲解
为了加快网站的解析速度,可以把动态页面和静态页面由不同的服务器来解析,加快解析速度。降低原 来单个服务器的压力。 简单来说,就是使用正则表达式匹配过滤,然后交个...
[阅读全文]
-
-
-
-
-
网友评论