loop_detect_status

The `loop_detect_status` directive configures the HTTP status code returned when a request exceeds the allowed loop limit in NGINX.

Syntaxloop_detect_status code;
Default508
Contexthttp, server, location
Arguments1

Description

The loop_detect_status directive is part of the ngx_http_loop_detect_module, which enables NGINX to manage and prevent request loops when dealing with CDN headers. By specifying this directive, users can define a custom HTTP status code that NGINX will return when the number of allowed request loops (set by the directive loop_detect_max_allow_loops) is exceeded. This status code must fall within the range of client and server error codes, specifically between 400 and 599.

When enabled through the loop_detect directive, the module monitors incoming requests for the CDN-Loop header, which indicates the path an HTTP request has taken through various CDNs. If an incoming request's loop count surpasses the configured maximum, NGINX will respond with the HTTP status code specified by loop_detect_status. This allows developers and sysadmins to manage loop situations gracefully and inform clients about the state of their requests appropriately.

It's important to choose a status code that makes sense within the context of your application; for instance, a 508 (Loop Detected) is commonly used for situations where an infinite loop has been detected, making it an appropriate choice in this case. Adopting an appropriate status code not only aids in developer debugging but also communicates more effectively with clients about the nature of the error.

Config Example

location / {
    loop_detect on;
    loop_detect_cdn_id my_cdn_id;
    loop_detect_status 508;
    loop_detect_max_allow_loops 10;
    proxy_set_header CDN-Loop $loop_detect_proxy_add_cdn_loop;
    proxy_pass http://example.upstream.com;
}

Ensure that the status code is between 400 and 599; otherwise, NGINX will reject the configuration.

Using a status code that does not communicate the right issue to clients may lead to confusion.

← Back to all directives