limit_rate_after

The 'limit_rate_after' directive allows you to specify a certain amount of data that can be sent to a client before restricting the rate.

Syntaxlimit_rate_after size;
Defaultnone
Contexthttp, server, location, if in location
Arguments1

Description

The 'limit_rate_after' directive in NGINX is used to control the bandwidth used by a client when downloading a file. It allows the configuration of a threshold after which the transfer rate will be limited. The directive is beneficial in scenarios where you want to provide an initial burst of bandwidth to improve the user experience but wish to restrict the bandwidth thereafter to manage resources better. It can be set at various context levels like http, server, and location, which provides flexibility based on your application's need.

When a client requests a resource, if the amount of data sent is less than the specified limit, NGINX serves the data without imposing any limitation on the rate. Once the total data sent exceeds the specified number defined in 'limit_rate_after', NGINX will then start to throttle the transfer rate based on the 'limit_rate' directive. This behavior enables website owners and administrators to allow certain users or requests to experience higher speeds initially, while still keeping resource usage under control when their download reaches a threshold. The argument for 'limit_rate_after' is the byte limit where this rate limiting becomes active.

It’s important to note that the directive requires careful configuration, especially in conjunction with the 'limit_rate' directive, to ensure that the desired user experience is achieved without overloading the server's bandwidth.

Config Example

server {
    location /downloads {
        limit_rate_after 1m;
        limit_rate 256k;
    }
}

Ensure 'limit_rate' is defined as well, as 'limit_rate_after' only acts after this directive is triggered.

Misconfiguring 'limit_rate_after' without 'limit_rate' could result in unexpected bandwidth behavior.

Overly large values can lead to excessive resource consumption unless carefully managed.

← Back to all directives