From 5bb44fdbcb196a65c7a09aa86a72635dac6e12ff Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 27 Apr 2026 11:41:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(converter):=20try=5Ffiles=20=E4=B9=9F?= =?UTF-8?q?=E4=BD=9C=E4=B8=BA=E9=9D=99=E6=80=81=E7=B1=BB=E5=9E=8B=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=9D=A1=E4=BB=B6=EF=BC=8C=E7=BB=A7=E6=89=BF=20server?= =?UTF-8?q?=20=E7=BA=A7=E5=88=AB=20root/index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - classifyLocation 将 try_files 也识别为静态类型 - 静态配置自动继承 server 级别的 root 和 index(如果未指定) Co-Authored-By: Claude Opus 4.7 --- internal/converter/nginx/converter.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/internal/converter/nginx/converter.go b/internal/converter/nginx/converter.go index 5ac1ae9..eaed012 100644 --- a/internal/converter/nginx/converter.go +++ b/internal/converter/nginx/converter.go @@ -284,13 +284,20 @@ func convertServerBlock(d *Directive, upstreams map[string]*upstreamInfo, result // If server-level root is defined but no explicit location / static config exists, // create a default static configuration for "/". // However, if location / is a proxy, don't create static config. + // Also, fill empty root in existing static configs with server-level root. if serverRoot != "" { hasRootLocation := false - // Check if there's already a static config for "/" - for _, s := range server.Static { - if s.Path == "/" { + for i := range server.Static { + // Inherit server-level root if location has no root specified + if server.Static[i].Root == "" { + server.Static[i].Root = serverRoot + } + // Inherit server-level index if location has no index specified + if len(server.Static[i].Index) == 0 && len(serverIndex) > 0 { + server.Static[i].Index = serverIndex + } + if server.Static[i].Path == "/" { hasRootLocation = true - break } } // Check if location / is a proxy @@ -526,6 +533,7 @@ func classifyLocation(d *Directive, result *ConvertResult) locationClassificatio // Classify based on content. hasProxyPass := false hasRootOrAlias := false + hasTryFiles := false hasRedirect := false for i := range d.Block { @@ -534,6 +542,8 @@ func classifyLocation(d *Directive, result *ConvertResult) locationClassificatio hasProxyPass = true case "root", "alias": hasRootOrAlias = true + case "try_files": + hasTryFiles = true case "return": if len(d.Block[i].Args) > 0 { code, err := strconv.Atoi(d.Block[i].Args[0]) @@ -555,7 +565,7 @@ func classifyLocation(d *Directive, result *ConvertResult) locationClassificatio Message: "location has both proxy_pass and root/alias; proxy_pass takes priority", }) } - case hasRootOrAlias: + case hasRootOrAlias || hasTryFiles: class.LocType = "static" case hasRedirect: class.LocType = redirectType