...
|
...
|
@@ -102,25 +102,7 @@ function rate_limit() |
|
|
ngx.exit(ngx.HTTP_OK)
|
|
|
end
|
|
|
|
|
|
-- do limit by ip+method, max qps is [max_per_sencond / 10]
|
|
|
local ip = ngx.var.real_ip
|
|
|
if not ip then
|
|
|
return
|
|
|
end
|
|
|
local key = ip .. ":" .. req_uri_method
|
|
|
local max_qps_ip = max_per_sencond / 10
|
|
|
if max_qps_ip <= default_minimal_ip_method_qps then
|
|
|
max_qps_ip = default_minimal_ip_method_qps
|
|
|
end
|
|
|
local ret = limit("yh:ngx:limitIP:" .. key, max_qps_ip)
|
|
|
if not ret then
|
|
|
ngx.header["Content-Type"]="application/json;charset=utf-8"
|
|
|
local rsp_body = '{"code":' .. err_code .. ',"message":"'.. err_msg .. '"}'
|
|
|
ngx.say(rsp_body)
|
|
|
ngx.exit(ngx.HTTP_OK)
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
...
|
...
|
|