我可以使用这样的 Caddyfile 拥有一个具有多个域的服务器(+ https 和 LetsEncrypt):
site1.com {
reverse_proxy localhost:3001
}
site2.com {
reverse_proxy localhost:3002
}
site3.com {
reverse_proxy localhost:3003
}
Run Code Online (Sandbox Code Playgroud)
但我想在没有 Caddyfile 的情况下运行 caddy,并且我想通过管理 API 动态添加此类代理。
他们有一个API,但我不明白如何在不需要 Caddyfile 的情况下为 caddy 添加新的反向代理。
我正在寻找此请求的 JSON 格式,它可以是这样的(伪请求):
curl localhost:2019/load \
-X POST \
-H "Content-Type: application/json" \
-data "{'domain': 'site1.com', 'tls': 'yes', 'proxy': 'http://localhost:3001'}"
curl localhost:2019/load \
-X POST \
-H "Content-Type: application/json" \
-data "{'domain': 'site2.com', 'tls': 'yes', 'proxy': 'http://localhost:3002'}"
Run Code Online (Sandbox Code Playgroud)
是否可以仅通过 API 添加反向代理?我使用的是Caddy v2.0
这不是caddy adapt你需要的吗?
> caddy adapt --config /path/to/Caddyfile
{"apps":{"http":{"servers":{"srv0":{"listen":[":443"],"routes":[{"match":[{"host":["site1.com"]}],"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"localhost:3001"}]}]}]}],"terminal":true},{"match":[{"host":["site2.com"]}],"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"localhost:3002"}]}]}]}],"terminal":true},{"match":[{"host":["site3.com"]}],"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"localhost:3003"}]}]}]}],"terminal":true}]}}}}}
Run Code Online (Sandbox Code Playgroud)
https://caddyserver.com/docs/getting-started
| 归档时间: |
|
| 查看次数: |
2862 次 |
| 最近记录: |