Files
diary-news/Caddyfile
Mavis eaa4aa6604 fix: Caddy 用 handle_path 自动 strip /api 前缀
之前的 reverse_proxy /api/* 直接转发保留路径,导致 api 收到 /api/v1/articles
而实际路由是 /v1/articles(API_PREFIX)。改用 handle_path。
2026-06-07 23:13:51 +08:00

40 lines
794 B
Caddyfile

{
# 全局选项
auto_https off
admin off
log {
level info
output stdout
}
}
# 如果 DOMAIN 为空,直接走 80 端口 HTTP(自签证书后面再补)
# 如果有域名,改用下面的 https 配置块
http://{$DOMAIN:NEWS_DOMAIN_FALLBACK} {
# /api/* 转发到 api:8000,handle_path 会自动 strip 匹配的 /api 前缀
handle_path /api/* {
reverse_proxy api:8000
}
# 其余走前端 SPA
handle {
reverse_proxy frontend:80
}
encode gzip zstd
# 日志
log {
output stdout
format console
}
}
# 如果有域名,启用自动 HTTPS(取消下面注释,并把上面块注释)
# {$DOMAIN} {
# reverse_proxy /api/* api:8000
# reverse_proxy /* frontend:80
# encode gzip zstd
# }