一聚教程网:一个值得你收藏的教程网站

热门教程

nginx如何防止cc攻击

时间:2026-08-29 07:48:50 编辑:袖梨 来源:一聚教程网

在nginx中预防cc攻击的方法

用户在正常访问网站时,与服务器建立的连接一般不会超过20个,可以通过以下脚本禁止连接数过大的IP访问。

#!/bin/shstatus=`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 ]thenecho IP:$IP is over $NUM, BAN IT!/sbin/iptables -I INPUT -s $IP -j DROPfi

热门栏目