-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCaddyfile.example
More file actions
99 lines (93 loc) · 3.97 KB
/
Caddyfile.example
File metadata and controls
99 lines (93 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Caddy + AegisGate 对公网暴露示例
#
# 架构:客户端 → https://api.example.com/v1/__gw__/t/8317/... → Caddy → AegisGate:18080 → localhost:8317
#
# reverse_proxy 目标地址按部署方式选择:
# - Caddy 与网关在同一 docker compose 网络:aegisgate:18080(Docker 服务名解析)
# - Caddy 在宿主机,网关在 Docker:127.0.0.1:18080(compose 已映射端口)
# - Caddy 与网关都在宿主机:127.0.0.1:18080
# - Caddy 在另一台机器:<网关机器IP>:18080
#
# 要点:
# - flush_interval -1:SSE 流式不缓冲,必须设置
# - response_header_timeout 660s:长时间推理不超时
# - /__gw__/* 返回 403:管理接口不暴露到公网
# - X-Aegis-Proxy-Token:Caddy ↔ AegisGate 信任凭证(可选,启用后网关可识别来自 Caddy 的请求)
# - 管理后台建议单独域名直连上游,不经网关
# - Caddy 只做 TLS + 转发,路由逻辑全在网关内部
#
# 需 80/443 开放;证书由 Caddy 自动申请
# 前端静态站点(可选,与网关无关;如不需要可删除整段)
# example.com, www.example.com {
# header {
# X-Content-Type-Options "nosniff"
# X-Frame-Options "SAMEORIGIN"
# Referrer-Policy "strict-origin-when-cross-origin"
# Permissions-Policy "geolocation=(), microphone=(), camera=()"
# -Server
# }
# header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
# root * /srv/www
# file_server
# }
# API:先经 AegisGate 安检与过滤,再由网关转发到上游
# reverse_proxy 目标按实际部署方式填写(见文件头部说明)
api.example.com {
header {
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
Referrer-Policy "strict-origin-when-cross-origin"
X-XSS-Protection "1; mode=block"
-Server
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
}
# 管理端点不对公网开放,避免通过反代触发 /__gw__ 管理操作
@gw_admin path /__gw__ /__gw__/*
respond @gw_admin "forbidden" 403
# 拦截扫描器探测的静态资源路径,不转发到网关(减少日志噪音)
@scanner_probe {
path /assets/* /static/* /js/* /css/* /images/* /img/* /fonts/*
path /robots.txt /favicon.ico /sitemap.xml /.env /wp-login.php /wp-admin/*
path /.git/* /.svn/* /.DS_Store /server-status /server-info
path /phpmyadmin/* /pma/* /admin/* /administrator/* /cgi-bin/*
}
respond @scanner_probe 404
# 仅允许 API 路径(/v1/ /v2/)通过,其余非 API 路径直接 404
@not_api {
not path /v1/* /v2/*
}
respond @not_api 404
# Caddy 在宿主机时改为 127.0.0.1:18080(见文件头部说明)
reverse_proxy 127.0.0.1:18080 {
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
header_up X-Real-IP {remote_host}
# Caddy ↔ AegisGate 信任凭证(可选)
# 值来自 config/aegis_proxy_token.key(首次启动自动生成)
# 启用方式:设置 Caddy 环境变量 AEGIS_PROXY_TOKEN 后取消下行注释
# header_up X-Aegis-Proxy-Token {env.AEGIS_PROXY_TOKEN}
flush_interval -1
transport http {
response_header_timeout 660s
read_timeout 660s
write_timeout 660s
}
}
}
# 上游管理后台(可选):直连上游,不经过网关。
# 按实际上游地址和端口替换(CLIProxyAPI=8317, Sub2API=8080, AIClient-2-API=3000)。
# 生产环境建议加 IP 白名单限制公网访问。
# panel.example.com {
# @allowed remote_ip 你的管理IP/32
# handle @allowed {
# reverse_proxy localhost:8317 {
# flush_interval -1
# transport http {
# response_header_timeout 660s
# read_timeout 660s
# write_timeout 660s
# }
# }
# }
# respond "forbidden" 403
# }