Files
termi-blog/deploy/caddy/Caddyfile.tohka.example

84 lines
2.2 KiB
Caddyfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# termi-blog / tohka Caddyfile 模板
#
# 说明:
# - 这是“参考模板”,不是已部署配置
# - 适合 tohka 上“宿主机大 Caddyfile -> localhost 端口 -> Docker 容器”的模式
# - 默认假设:
# - frontend 绑定到 localhost:4321
# - admin 绑定到 localhost:4322
# - backend 绑定到 localhost:5150
# -----------------------------
# 方案 A推荐子域名分流
# -----------------------------
blog.init.cool {
import common
reverse_proxy http://localhost:4321
}
admin.blog.init.cool {
import common
# 推荐admin 域名整体走 TinyAuth / Pocket ID 保护
# tohka 现成片段会转发:
# Remote-User / Remote-Name / Remote-Email / Remote-Groups
import tinyauth
# admin 静态资源与后台 API 都走同一受保护域名
# 如果 backend 开启了 TERMI_ADMIN_PROXY_SHARED_SECRET
# 记得在转发 /api 到 backend 时补一个共享密钥头,避免直接伪造 Remote-User。
handle /api/* {
reverse_proxy http://localhost:5150 {
header_up X-Termi-Proxy-Secret {$TERMI_ADMIN_PROXY_SHARED_SECRET}
}
}
handle {
reverse_proxy http://localhost:4322
}
}
# 前台公开 API 可单独暴露(评论 / 搜索 / AI 问答等)
api.blog.init.cool {
import common
reverse_proxy http://localhost:5150
}
# -----------------------------
# 方案 B单域名 + 路径分流
# -----------------------------
#
# 注意:
# 1. /admin 方案要求 admin 构建时设置:
# VITE_ADMIN_BASENAME=/admin
# 2. /admin 使用 handle_path进入 admin 容器前会去掉 /admin 前缀
# 3. /api 不要用 handle_pathbackend 当前路由本身就包含 /api 前缀
# 4. 如果 /admin 也要调用受保护 API需要同时把 /api 接到 backend 并加 tinyauth
init.cool {
import common
handle_path /admin* {
import tinyauth
reverse_proxy http://localhost:4322
}
handle /api* {
import tinyauth
reverse_proxy http://localhost:5150 {
header_up X-Termi-Proxy-Secret {$TERMI_ADMIN_PROXY_SHARED_SECRET}
}
}
handle {
reverse_proxy http://localhost:4321
}
}
# 部署时 backend 记得配套:
# TERMI_ADMIN_TRUST_PROXY_AUTH=true
# TERMI_ADMIN_LOCAL_LOGIN_ENABLED=false
# TERMI_ADMIN_PROXY_SHARED_SECRET=<随机长字符串>