diff --git a/.gitignore b/.gitignore index 4facb6f..3685058 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,4 @@ apps/* # 运行时缓存文件 .cache/ +tmp/ diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..deea056 --- /dev/null +++ b/Caddyfile @@ -0,0 +1,59 @@ +# Caddy 配置文件 - 前端静态文件 + 后端 API 反向代理 +# 最小化配置,符合 Caddy 2.x 最佳实践 + +{ + 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 + } +} + diff --git a/caddy b/caddy new file mode 100755 index 0000000..89ac751 Binary files /dev/null and b/caddy differ