# Caddy 配置文件 - 前端静态文件 + 后端 API 反向代理 # 最小化配置,符合 Caddy 2.x 最佳实践 # # 使用说明: # 1. 生产环境:将 :8080 替换为你的域名(如 example.com) # 2. 确保域名 DNS 已解析到服务器 IP # 3. 确保防火墙开放 80 和 443 端口 # 4. Caddy 会自动从 Let's Encrypt 获取和续期 SSL 证书 # 5. 可选:取消注释 email 行,用于证书到期通知 { # 自动 HTTPS 配置(Let's Encrypt) # email your-email@example.com # 可选:用于证书到期通知 # acme_ca https://acme-v02.api.letsencrypt.org/directory # 默认使用 Let's Encrypt log { output stdout format console } } :8080 { # 静态资源缓存 @static { file path *.js *.css *.png *.jpg *.jpeg *.gif *.svg *.ico *.woff *.woff2 *.ttf *.eot } header @static Cache-Control "public, max-age=31536000, immutable" # HTML 不缓存 @html { file path *.html } header @html Cache-Control "no-cache" # 安全头 header { X-Content-Type-Options "nosniff" X-Frame-Options "SAMEORIGIN" Referrer-Policy "strict-origin-when-cross-origin" } # API 反向代理 handle /api/* { reverse_proxy localhost:9001 { header_up X-Real-IP {remote_host} header_up X-Forwarded-For {remote_host} header_up X-Forwarded-Proto {scheme} } } # 后端 API 反向代理 handle /jingrow/* { reverse_proxy localhost:9001 { header_up X-Real-IP {remote_host} header_up X-Forwarded-For {remote_host} header_up X-Forwarded-Proto {scheme} } } # 前端静态文件 + SPA 路由支持 handle { root * apps/jingrow/frontend/dist encode gzip zstd try_files {path} /index.html file_server } }