基于lua页面访问限制控制(转载乌云)

if ($cookie_say != "hbnl"){
    add_header Set-Cookie "say=hbnl";
    rewrite .* "$scheme://$host$uri" redirect;
}


if ($cookie_say != "hbnl$remote_addr"){
    add_header Set-Cookie "say=hbnl$remote_addr";
    rewrite .* "$scheme://$host$uri" redirect;
}




rewrite_by_lua '
 
    local random = ngx.var.cookie_random
 
    if(random == nil) then
        random = math.random(999999)
    end
 
    local token = ngx.md5("opencdn" .. ngx.var.remote_addr .. random)
    if (ngx.var.cookie_token ~= token) then
        ngx.header["Set-Cookie"] = {"token=" .. token, "random=" .. random}
        return ngx.redirect(ngx.var.scheme .. "://" .. ngx.var.host .. ngx.var.uri)
    end
 
';



http://drops.wooyun.org/tips/734 参考



本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/1581816

上一篇:request对象常用API 获取请求参数的值 request应用 MVC设计模式


下一篇:《VMware vSphere企业运维实战》——1.7 存储的选择