首先varnish很少做这个,一般通过iptable来做,或者用apache或者nginx的模块,如:mod_limitipconn
IPtable可以限制同一个IP的连接数,连接时长等等。
推荐看这篇文章,这个朋友也遇到了同样的问题,
http://www.rocchi.us/2012/08/mitigate-ddos-with-iptables-and-ipt_recent/
此外,如果用varnish的话,可以在varnish里面检查一下user-agent,user-agent检查一下。
if ( req.http.user-agent ~ "^$"
|| req.http.user-agent ~ "^Java"
|| req.http.user-agent ~ "^Jakarta"
|| req.http.user-agent ~ "^Ruby"
|| req.http.user-agent ~ "IDBot"
|| req.http.user-agent ~ "Wget"
|| req.http.user-agent ~ "id-search"
|| req.http.user-agent ~ "User-Agent"
|| req.http.user-agent ~ "ConveraCrawler"
|| req.http.user-agent ~ "^Mozilla$"
|| req.http.user-agent ~ "libwww"
) {
error 403 "You are banned from this site. Please contact via a different client configuration if you believe that this is a mistake.";
}