在nginx中预防cc攻击的方法
用户在正常访问网站时,与服务器建立的连接一般不会超过20个,可以通过以下脚本禁止连接数过大的IP访问。
#!/bin/sh status=`netstat -na|awk '$5 ~ /[0-9]+:[0-9]+/ {print $5}' |awk -F ":" -- '{print $1}' |sort -n|uniq -c |sort -n|tail -n 1` NUM=`echo $status|awk '{print $1}'` IP=`echo $status|awk '{print $2}'` result=`echo "$NUM > 150" | bc` \\当IP的访问次数超过150时,对该IP进行屏蔽 if [ $result = 1 ] then echo IP:$IP is over $NUM, BAN IT! /sbin/iptables -I INPUT -s $IP -j DROP fi
文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/155272.html<