delay
The 'delay' directive introduces an intentional delay in processing requests for a specified duration.
Description
The 'delay' directive is used in NGINX to introduce a pause in request processing based on a specified time duration. It can be set within various contexts, including http, server, and location blocks. This directive takes one argument that represents the delay time in milliseconds, seconds, or minutes. When enabled, it temporarily halts the handling of the request until the specified delay duration has elapsed. The maximum duration is limited only by the configuration of the server and available resources.
When a request with a delay is processed, the request's write event is placed in a delayed state. This means that, during the delay, the server is not handling any additional events for this particular request. After the specified delay period, the server transitions back to handling the normal processing routine. If the request experiences an internal redirect, another delay will be triggered, extending the total wait time. This module is useful for simulating slow responses, throttling requests, or testing client behavior under delayed server responses.
It's essential to configure appropriate timeout settings to avoid unintended server overload or unresponsive states due to excessive delays. The delay directive should be used judiciously, considering the overall server performance and client experience.
Config Example
location = /slow {
delay 10s;
# other configurations
}Internal redirects will trigger a separate delay, potentially compounding the wait time.
Ensure that any timeout configurations are set correctly to prevent excessive delays from causing request failures.