fix(gateway): 门户段重复 root 导致 nginx -t 失败
v52 部署被 apply 的校验拦下("root directive is duplicate"):writeErrorPages 已写过 root /app/portal;,我又在 portal 分支写了一次。移除重复行,并加单测断言 该指令在生成结果里恰好出现一次。回滚机制按预期工作,服务未中断。
This commit is contained in:
@ -259,7 +259,8 @@ func writeRouteServer(b *strings.Builder, cfg *GatewayConfig, r Route) error {
|
||||
if routeKind(r) == "portal" {
|
||||
// 门户首页交给 admin-server 渲染(pageInfo 可配置 + 支持数据卷整页覆盖),
|
||||
// 静态资源仍由本容器提供(root /app/portal)。
|
||||
b.WriteString(" root /app/portal;\n")
|
||||
// 注意:不要在这里再写 root —— writeErrorPages 已经写过一次,
|
||||
// 重复会让 nginx -t 报 "root directive is duplicate"(本轮真实踩到)。
|
||||
b.WriteString(" location = / { proxy_pass http://127.0.0.1:3005/portal-page; proxy_set_header Host $host; proxy_redirect off; }\n")
|
||||
b.WriteString(" location / { try_files $uri $uri/ /404.html; }\n}\n\n")
|
||||
return nil
|
||||
|
||||
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -372,3 +373,14 @@ func TestPortalKindUsesRenderer(t *testing.T) {
|
||||
t.Fatalf("静态资源根目录丢失:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
// nginx 不允许同一 server 段内重复的 root 指令(实测报 emerg)。
|
||||
func TestPortalKindNoDuplicateRoot(t *testing.T) {
|
||||
out, err := RenderGatewayConf(&GatewayConfig{ListenPort: 8081, Routes: []Route{{Host: "p.com", Kind: "portal"}}})
|
||||
if err != nil {
|
||||
t.Fatalf("渲染失败: %v", err)
|
||||
}
|
||||
if strings.Count(out, "root /app/portal;") != 1 {
|
||||
t.Fatalf("root 指令重复(应恰好 1 次):\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user