跳转至

denycc配置

CC攻击默认是全局,我们可以单独定制匹配规则

Bash
function denycc()
    if CCDeny then
        --定义匹配uri
        tzy_match = string.match(ngx.var.uri,'/index.php?app=course&mod=Video&act=updateLearn')
        local uri=ngx.var.uri
        CCcount=tonumber(string.match(CCrate,'(.*)/'))
        CCseconds=tonumber(string.match(CCrate,'/(.*)'))
        local token = getClientIp()..uri
        local limit = ngx.shared.limit
        local req,_=limit:get(token)
        if req then
            if req > CCcount then
                 ngx.exit(444)
                return true
            else
                 limit:incr(token,1)
            end
        else
            limit:set(token,1,CCseconds)
        end
    end
    return false
end