negiix 更换成 caddy

This commit is contained in:
yml2213
2026-06-11 04:17:36 +08:00
parent 4b9ac0598f
commit c0403fc1ea
10 changed files with 194 additions and 82 deletions
+56
View File
@@ -0,0 +1,56 @@
{
email {$CADDY_EMAIL}
}
# 反代到后端时,用 Caddy 实测到的对端地址覆盖 X-Real-IP,
# 防止客户端伪造 X-Forwarded-For 影响限流、审计和支付下单的 client_ip。
(backend_proxy) {
header_up X-Real-IP {remote_host}
}
{$CADDY_DOMAIN} {
encode zstd gzip
header {
Strict-Transport-Security "max-age=31536000"
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
Referrer-Policy "strict-origin-when-cross-origin"
Permissions-Policy "camera=(), microphone=(), geolocation=()"
}
# 聊天 SSE 长连接:关闭缓冲,逐条推送。
@api_sse {
path /api/chats/events /api/admin/chats/events
}
handle @api_sse {
reverse_proxy backend:8080 {
flush_interval -1
import backend_proxy
}
}
handle /api/* {
# 后端上传上限 10MB,这里前置拦掉超大请求体(留 1MB 余量)。
request_body {
max_size 11MB
}
reverse_proxy backend:8080 {
import backend_proxy
}
}
handle /health {
reverse_proxy backend:8080 {
import backend_proxy
}
}
# 其余流量返回前端静态资源,未命中的路径交给 SPA 处理。
handle {
root * /srv/dist
try_files {path} /index.html
file_server
}
}
+14
View File
@@ -0,0 +1,14 @@
# 第一阶段:构建前端静态资源
FROM node:24-alpine AS build
WORKDIR /src
COPY frontend/package*.json ./
RUN npm install
COPY frontend/ .
RUN npm run build
# 第二阶段:Caddy 作为公网入口,同时托管前端 dist
FROM caddy:2.10-alpine
COPY --from=build /src/dist /srv/dist
EXPOSE 80 443