最简易:通过cookie识别访问者身份结合302 来抵御CC攻击,在 location段加入以下代码:
CC攻击简易预防
if ($cookie_say != "isuike"){
add_header Set-Cookie "say=isuike";
rewrite .* "$scheme://$host$uri" redirect;
}
2.简易增强:如果cc带了cookie,那么可以加上用户ip的识别并写入到cookie验证中,结合302,在 location段加入以下代码:
if ($cookie_say != "isuike$remote_addr"){
add_header Set-Cookie "say=isuike$remote_addr";
rewrite .* "$scheme://$host$uri" redirect;
}
3.理论上的完美版:用salt加散列,这里需要nginx_lua模块,同样,加入以下代码:
rewrite_by_lua '
local say = ngx.md5("isuike" .. ngx.var.remote_addr)
if (ngx.var.cookie_say ~= say) then
ngx.header["Set-Cookie"] = "say=" .. say
return ngx.redirect(ngx.var.scheme .. "://" .. ngx.var.host .. ngx.var.uri)
end
';
这些方法可以解决过CDN,无法识别ip访问频率等因素导致的攻击识别困难的CC类攻击防御。
1
1
1
[...]nginx 抵御 cc 类攻击的一些小技巧[...]
178910
707523
796431
796431
774904
774904
11643
11643
我来评论一下!