nginx
config_error
ai_generated
true
处理时发生重写或内部重定向循环
rewrite or internal redirection cycle while processing
ID: nginx/rewrite-or-internal-redirection-cycle
85%修复率
84%置信度
1证据数
2023-03-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 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 | — | — | — |
根因分析
重写规则或try_files指令导致无限循环,因为重写后的URI反复匹配同一个location块。
English
A rewrite rule or try_files directive causes an infinite loop because the rewritten URI matches the same location block repeatedly.
官方文档
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite解决方案
-
在重写规则中添加break标志:rewrite ^/old/(.*)$ /new/$1 break;
-
为目标URI使用单独的location以避免递归:location /new/ { ... } -
用try_files和命名location替换重写:try_files $uri @fallback; location @fallback { ... }
无效尝试
常见但无效的做法:
-
90% 失败
Logging doesn't break the cycle; it only helps debug.
-
70% 失败
This prevents external access but may still cycle internally if rewrite triggers same location.
-
95% 失败
Timeouts don't affect rewrite loops; they are unrelated.