fix(converter): try_files 也作为静态类型判断条件,继承 server 级别 root/index
- classifyLocation 将 try_files 也识别为静态类型 - 静态配置自动继承 server 级别的 root 和 index(如果未指定) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
78ca32748c
commit
5bb44fdbcb
@ -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,
|
// If server-level root is defined but no explicit location / static config exists,
|
||||||
// create a default static configuration for "/".
|
// create a default static configuration for "/".
|
||||||
// However, if location / is a proxy, don't create static config.
|
// 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 != "" {
|
if serverRoot != "" {
|
||||||
hasRootLocation := false
|
hasRootLocation := false
|
||||||
// Check if there's already a static config for "/"
|
for i := range server.Static {
|
||||||
for _, s := range server.Static {
|
// Inherit server-level root if location has no root specified
|
||||||
if s.Path == "/" {
|
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
|
hasRootLocation = true
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check if location / is a proxy
|
// Check if location / is a proxy
|
||||||
@ -526,6 +533,7 @@ func classifyLocation(d *Directive, result *ConvertResult) locationClassificatio
|
|||||||
// Classify based on content.
|
// Classify based on content.
|
||||||
hasProxyPass := false
|
hasProxyPass := false
|
||||||
hasRootOrAlias := false
|
hasRootOrAlias := false
|
||||||
|
hasTryFiles := false
|
||||||
hasRedirect := false
|
hasRedirect := false
|
||||||
|
|
||||||
for i := range d.Block {
|
for i := range d.Block {
|
||||||
@ -534,6 +542,8 @@ func classifyLocation(d *Directive, result *ConvertResult) locationClassificatio
|
|||||||
hasProxyPass = true
|
hasProxyPass = true
|
||||||
case "root", "alias":
|
case "root", "alias":
|
||||||
hasRootOrAlias = true
|
hasRootOrAlias = true
|
||||||
|
case "try_files":
|
||||||
|
hasTryFiles = true
|
||||||
case "return":
|
case "return":
|
||||||
if len(d.Block[i].Args) > 0 {
|
if len(d.Block[i].Args) > 0 {
|
||||||
code, err := strconv.Atoi(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",
|
Message: "location has both proxy_pass and root/alias; proxy_pass takes priority",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
case hasRootOrAlias:
|
case hasRootOrAlias || hasTryFiles:
|
||||||
class.LocType = "static"
|
class.LocType = "static"
|
||||||
case hasRedirect:
|
case hasRedirect:
|
||||||
class.LocType = redirectType
|
class.LocType = redirectType
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user