fix(gateway): 被代理站点的 favicon 免登录直通上游(而非门户静态文件/登录墙)

承接上一提交:把门户 favicon 从代理块里去掉后暴露两个问题:
- requireLogin 的站点 /favicon.ico 变成 302(浏览器标签与图标抓取都取不到);
- 而 favicon 本来就不该要求登录。

改为:代理块显式写
    location = /favicon.ico  { auth_request off; proxy_pass <上游>; ... }
    location = /favicon.svg  { auth_request off; proxy_pass <上游>; ... }
(https/自签上游附带 proxy_ssl_verify off)。
效果:浏览器标签显示各站点自己的图标、无需登录;抓取端也因此能在未登录时取到真实图标。
门户页/登录页/默认 404 块仍提供门户自己的 favicon。测试断言同步改为"直通上游"语义。
This commit is contained in:
HomeDash Bot
2026-09-13 08:52:41 +08:00
parent 3d1ed788f3
commit 9c0d9f2bb5
2 changed files with 40 additions and 17 deletions

View File

@ -306,6 +306,24 @@ func writeRouteServer(b *strings.Builder, cfg *GatewayConfig, r Route) error {
for _, p := range r.BypassPaths {
writeProxyLocation(b, r, p, true)
}
// favicon 免登录直通上游。
// 理由:① 图标不是敏感资源,未登录时浏览器标签也该显示站点自己的图标;
// ② 导航项/历史条目的图标抓取依赖它在未登录时可取。
// 之前这里是"在门户 root 里 try_files",等于把每个被代理站点的图标都换成门户图标
// (实测 pi / ittools / vikunja 存下了同一张门户图标)。
if up := strings.TrimSpace(r.Upstream); up != "" {
for _, fa := range []string{"/favicon.ico", "/favicon.svg"} {
fmt.Fprintf(b, " location = %s {\n auth_request off;\n proxy_pass %s;\n", fa, up)
b.WriteString(" proxy_set_header Host $host;\n")
b.WriteString(" proxy_set_header X-Real-IP $remote_addr;\n")
b.WriteString(" proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n")
b.WriteString(" proxy_set_header X-Forwarded-Proto $scheme;\n")
if r.InsecureTLS || strings.HasPrefix(strings.ToLower(up), "https://") {
b.WriteString(" proxy_ssl_verify off;\n")
}
b.WriteString(" proxy_redirect off;\n }\n")
}
}
writeProxyLocation(b, r, "", false)
b.WriteString("}\n\n")
return nil