loop_detect_max_allow_loops
The `loop_detect_max_allow_loops` directive sets the maximum number of allowed loops for requests to prevent infinite loops in CDN configurations.
Description
The loop_detect_max_allow_loops directive is part of the NGINX ngx_http_loop_detect_module, which leverages the CDN-Loop header to manage and detect request loops. This directive specifies the maximum number of hops a request can take through different CDN nodes before it is deemed to be in a loop and is subsequently blocked. By configuring this directive, administrators can protect their applications from excessive resource consumption and potential service downtime due to infinite request loops.
When a request passes through the CDN, each node appends its identifier to the CDN-Loop header. Each time a request reaches a server with loop detection enabled, NGINX evaluates the current number of hops against the specified loop_detect_max_allow_loops value. If the count exceeds this limit, NGINX will terminate the request and return the defined status code, signaling that the maximum allowable loops have been surpassed. This mechanism is especially crucial in complex multi-layered CDN environments where request cycles can lead to unresponsive services.
Config Example
http {
loop_detect on;
loop_detect_cdn_id my_cdn_id;
loop_detect_status 508;
loop_detect_max_allow_loops 5;
server {
listen 80;
server_name example.com;
location / {
proxy_set_header CDN-Loop $loop_detect_proxy_add_cdn_loop;
proxy_pass http://example.upstream.com;
}
}
}Setting a very low value may block legitimate requests that have a few hops, potentially degrading service.
Ensure the CDN-Loop header is correctly managed in your upstream services; otherwise, accurate loop detection may not be possible.
Exceeding the maximum allowed loops will not retry requests, which may impact application performance under certain failure conditions.