基于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 参考

你可能感兴趣的:(lua,限制控制)