1 个回答
代码示例如下:
lua_shared_dict limit_counter 10m;
server {
location / {
access_by_lua_block {
local limit_counter = ngx.shared.limit_counter
local key = ngx.var.binary_remote_addr
local req,_ = limit_counter:get(key)
if req then
if req > 100 then # 每秒100次阈值
ngx.exit(503)
else
limit_counter:incr(key,1)
end
else
limit_counter:set(key,1,1) # 过期时间1秒
end
}
}
}
发布于:2周前 (03-13) IP属地:四川省
我来回答
您需要 登录 后回答此问题!