limit_conn_status

The `limit_conn_status` directive sets the HTTP status code returned when a connection limit is exceeded.

Syntaxlimit_conn_status code;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The limit_conn_status directive in NGINX specifies the HTTP status code that will be returned to clients when their request exceeds the configured connection limits for a given context (http, server, or location). This directive allows administrators to customize the response behavior, enabling a more informative interface for users who may inadvertently attempt to establish more connections than permitted by the NGINX configuration.

When a limit configured by limit_conn is breached, instead of returning a default 503 Service Unavailable response, which may not provide meaningful feedback to users, the configured status code can be returned. This provides clarity, assisting in error handling processes for client applications. The status code must be a valid HTTP code, and generally, it is wise to avoid common success or redirection codes to prevent confusion.

To utilize this directive effectively, it is recommended to assess the expected behavior of client applications during limit breaches, as a status code other than 503 can alter how clients react to capacity issues. For example, a 429 Too Many Requests status may be appropriate, indicating that the user is being throttled for over-accessing resources. This directive can also be combined with logs tailored to monitor connection limit violations.

Config Example

http {
    limit_conn_zone $binary_remote_addr zone=addr:10m;
    limit_conn addr 10;
    limit_conn_status 429;
}

Ensure the status code is a valid HTTP response code to avoid unexpected behavior.

Using the directive in the wrong context may lead to configuration errors.

← Back to all directives