Rate Limit Requests per URL with Nginx

Posted on January 31, 2017 at 11:34 pm

You can rate limit requests per URL with Nginx. So lets say you want to limit requests on /v2/api URL to max 150 per minute independently from the remote IP address, you can do like this:

Add this inside http{} block:

limit_req_zone $server_name zone=one:100m rate=150r/m;

Then inside the server{} block add this:

location /v2/api {
    limit_req zone=one nodelay;
    # By default it returns error 503 (service unavailable)
    # To return error 429 (too many requests) add this
    limit_req_status 429;
}

Then restart Nginx service:

/etc/init.d/nginx restart

More information:

Module ngx_http_limit_req_module

Updated on February 1, 2017 at 11:15 pm

Receive updates via email

Other Posts

Updated Posts