V
V
votod2019-03-14 11:43:34
Nginx
votod, 2019-03-14 11:43:34

How to limit the number of API requests by key, not by ip?

How to use nginx to limit the number of requests, for a certain period of time, to a unique link? I need to limit the number of API requests not by IP, but by key using nginx. Everywhere where saw similar manuals use restrictions on IP.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2019-03-14
@Lynn

nginx.org/ru/docs/http/ngx_http_limit_req_module.h...
You can use anything as a key, not necessarily IP.
2 requests per 10 seconds is 12 requests per minute (12r/m)

limit_req_zone $arg_key zone=api:10m rate=12r/m;

location /какой-нужно {
    limit_req zone=api burst=1 nodelay;
}

How the limit works: https://ru.wikipedia.org/wiki/%D0%90%D0%BB%D0%B3%D...

B
Boris Korobkov, 2019-03-14
@BorisKorobkov

nginx.org/ru/docs/http/ngx_http_secure_link_module.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question