limit req - multiple url support
This commit is contained in:
@@ -58,9 +58,7 @@ local dnsbl_list = {% raw %}{{% endraw %}{% if DNSBL_LIST != "" %}{% set elemen
|
||||
local use_bad_behavior = {% if USE_BAD_BEHAVIOR == "yes" %}true{% else %}false{% endif +%}
|
||||
|
||||
-- limit req
|
||||
local use_req_limit = {% if USE_REQ_LIMIT == "yes" %}true{% else %}false{% endif +%}
|
||||
local limit_req_rate = "{{ LIMIT_REQ_RATE }}"
|
||||
local limit_req_burst = "{{ LIMIT_REQ_BURST }}"
|
||||
local use_limit_req = {% if USE_LIMIT_REQ == "yes" %}true{% else %}false{% endif +%}
|
||||
|
||||
-- remote API
|
||||
local use_remote_api = {% if USE_REMOTE_API == "yes" %}true{% else %}false{% endif +%}
|
||||
@@ -155,9 +153,28 @@ if use_bad_behavior and behavior.is_banned() then
|
||||
end
|
||||
|
||||
-- check if IP is banned because of "request limit"
|
||||
-- if use_req_limit and reqlimit.check() then
|
||||
-- ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||
-- end
|
||||
if use_limit_req then
|
||||
{% if USE_LIMIT_REQ == "yes" %}
|
||||
{% for k, v in all.items() %}
|
||||
{% if k.startswith("LIMIT_REQ_URL") and v != "" +%}
|
||||
{% set url = v %}
|
||||
{% set rate = all[k.replace("URL", "RATE")] if k.replace("URL", "RATE") in all else "1r/s" %}
|
||||
{% set burst = all[k.replace("URL", "BURST")] if k.replace("URL", "BURST") in all else "5" %}
|
||||
{% set delay = all[k.replace("URL", "DELAY")] if k.replace("URL", "DELAY") in all else "1" %}
|
||||
{% if url == "/" %}
|
||||
if limitreq.check("{{ rate }}", {{ burst }}, {{ delay }}) then
|
||||
ngx.exit(ngx.HTTP_TOO_MANY_REQUESTS)
|
||||
end
|
||||
{% else %}
|
||||
if ngx.var.uri == "{{ url }}" and limitreq.check("{{ rate }}", {{ burst }}, {{ delay }}) then
|
||||
ngx.exit(ngx.HTTP_TOO_MANY_REQUESTS)
|
||||
end
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
end
|
||||
|
||||
-- our redis client
|
||||
local redis_client = nil
|
||||
|
||||
Reference in New Issue
Block a user