nginx配置代码:
lua_shared_dict limit 10m;
server {
listen 80;
server_name localhost;
location / {
default_type text/html;
content_by_lua_file "/usr/local/openresty/nginx/conf/lua";
}
}
lua代码:
local ip = ngx.var.binary_remote_addr
local limit = ngx.shared.limit
local req,_=limit:get(ip)
if req then
limit:incr(ip,2)
ngx.say(req)
else
limit:set(ip,1,60)
end
如果 limit:incr(ip,2) ,则增加4,limit:incr(ip,4) 增加8,都是以2倍增加。