fix(site): 按 Host 注入租户标题与 SEO 信息

This commit is contained in:
2026-11-19 16:54:50 +08:00
parent e80a461182
commit 3492ecbe9b
12 changed files with 969 additions and 28 deletions
+36 -7
View File
@@ -86,6 +86,20 @@
respond 404
}
# /index.html 直接访问统一回到 /,避免拿到未注入租户信息的静态 HTML。
redir /index.html / 308
# HTML 文档请求交给后端按 Host 注入租户品牌;静态资源仍由 Caddy 直接返回。
@storefront_html {
not path /api /api/* /r /r/* /health /health/ready /assets /assets/* /site-bootstrap.js /apple-touch-icon.png /jieyou-favicon.svg /jieyou-apple-touch-icon.png /favicon.ico /robots.txt /sitemap.xml
not path_regexp "\.[A-Za-z0-9]{1,10}$"
}
handle @storefront_html {
reverse_proxy backend:8080 {
import backend_proxy
}
}
# 其余流量返回主站/分销前台前端静态资源。
handle {
root * /srv/dist
@@ -94,15 +108,32 @@
}
}
# 仅容器内网访问:后端通过该端点读取构建后的 index.html,
# 用于按 Host 注入租户标题、图标和 SEO 信息。不要把 8081 映射到宿主机端口。
:8081 {
handle /__internal/storefront-shell.html {
root * /srv/dist
rewrite * /index.html
header Cache-Control "no-store"
file_server
}
respond 404
}
# 后台 HTML 也由后端按 Host 注入品牌;/assets 等静态资源由 storefront 的最终 handle 返回。
(admin_html) {
reverse_proxy backend:8080 {
import backend_proxy
}
}
# 主站与过渡子域名共享同一套配置:域名迁移期间新旧域名同时可访问,
# 避免 DNS 缓存未生效导致部分用户打不开。迁移完成后可移除 h5.{$CADDY_DOMAIN}。
{$CADDY_DOMAIN}, h5.{$CADDY_DOMAIN} {
# 主站后台隐藏入口只在本域名提供静态资源;分销站点域名由 storefront 片段统一 404。
# 主站后台隐藏入口只在本域名提供;HTML 由后端注入,静态资源仍由 storefront 返回。
@main_admin path {$ADMIN_BASE_PATH:/manage-7x9k2p} {$ADMIN_BASE_PATH:/manage-7x9k2p}/*
handle @main_admin {
root * /srv/dist
try_files {path} /index.html
file_server
import admin_html
}
import storefront
@@ -113,9 +144,7 @@
{$TENANT_JIEYOU_DOMAIN:tenant-jieyou.invalid} {
@tenant_admin path {$ADMIN_BASE_PATH:/manage-7x9k2p} {$ADMIN_BASE_PATH:/manage-7x9k2p}/*
handle @tenant_admin {
root * /srv/dist
try_files {path} /index.html
file_server
import admin_html
}
import storefront