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 say = ngx.md5("opencdn" ..ngx.var.remote_addr) if (ngx.var.cookie_say ~= say) then ngx.header["Set-Cookie"]= "say=" .. say returnngx.redirect(ngx.var.scheme .. "://" .. ngx.var.host ..ngx.var.uri) end '; |
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{ ... limit_req_zone $cookie_tokenzone=session_limit:3m rate=1r/s; } |
limit_req zone=session_limit burst=5; |
http{ ... http://www.server110.com/ limit_req_zone $cookie_token zone=session_limit:3mrate=1r/s; limit_req_zone $binary_remote_addr $uri zone=auth_limit:3mrate=1r/m; } location /{ limit_req zone=session_limit burst=5; rewrite_by_lua ' local random = ngx.var.cookie_random if (random == nil) then return ngx.redirect("/auth?url=" .. ngx.var.request_uri) end local token = ngx.md5("opencdn" .. ngx.var.remote_addr ..random) if (ngx.var.cookie_token ~= token) then return ngx.redirect("/auth?url=".. ngx.var.request_uri) end '; } location /auth { limit_req zone=auth_limit burst=1; if ($arg_url = "") { return 403; } access_by_lua ' local random = math.random(9999) 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.arg_url) end '; } |
欢迎光临 360°网站管家_运维学院_提供最新最全的服务器运维视频教程与网站维护视频教程 (http://bbs.360wzgj.com/) | Powered by Discuz! X3.2 |