nginx
config_error
ai_generated
true
rewrite or internal redirection cycle while processing
ID: nginx/rewrite-or-internal-redirection-cycle
85%Fix Rate
84%Confidence
1Evidence
2023-03-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| nginx 1.18.0 | active | — | — | — |
| nginx 1.20.2 | active | — | — | — |
| nginx 1.22.1 | active | — | — | — |
| nginx 1.24.0 | active | — | — | — |
| nginx 1.25.3 | active | — | — | — |
Root Cause
A rewrite rule or try_files directive causes an infinite loop because the rewritten URI matches the same location block repeatedly.
generic中文
重写规则或try_files指令导致无限循环,因为重写后的URI反复匹配同一个location块。
Official Documentation
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewriteWorkarounds
-
85% success Add a break flag to the rewrite rule: rewrite ^/old/(.*)$ /new/$1 break;
Add a break flag to the rewrite rule: rewrite ^/old/(.*)$ /new/$1 break;
-
90% success Use a separate location for the target URI to avoid recursion: location /new/ { ... }
Use a separate location for the target URI to avoid recursion: location /new/ { ... } -
80% success Replace rewrite with try_files and a named location: try_files $uri @fallback; location @fallback { ... }
Replace rewrite with try_files and a named location: try_files $uri @fallback; location @fallback { ... }
中文步骤
在重写规则中添加break标志:rewrite ^/old/(.*)$ /new/$1 break;
为目标URI使用单独的location以避免递归:location /new/ { ... }用try_files和命名location替换重写:try_files $uri @fallback; location @fallback { ... }
Dead Ends
Common approaches that don't work:
-
90% fail
Logging doesn't break the cycle; it only helps debug.
-
70% fail
This prevents external access but may still cycle internally if rewrite triggers same location.
-
95% fail
Timeouts don't affect rewrite loops; they are unrelated.