caddy - Caddy:如何通过 API 添加多个反向代理而不使用 Caddyfile?
问题描述
我可以使用这样的 Caddyfile (+ https withletsencrypt) 拥有一个具有多个域的服务器:
site1.com {
reverse_proxy localhost:3001
}
site2.com {
reverse_proxy localhost:3002
}
site3.com {
reverse_proxy localhost:3003
}
但是我想在没有 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'}"
是否可以仅通过 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}]}}}}}
推荐阅读
- javascript - 带有背景剪辑的内联元素:文本;在 Safari 中
- graphql - Strapi GraphQL - 如何创建分页?
- r - 将数据从excel导出到R
- python - 输入太大的标准python错误?
- amazon-web-services - AWS MediaConvert:ImageInserter 未按预期工作
- html - 如何获取段落旁边的表格?
- c# - 在索赔中搜索
- android - 如何在应用程序颤振飞镖上添加谷歌教室等功能
- ruby-on-rails - 运行rails c后的LoadError
- javascript - PeerJS屏幕共享卡在屏幕共享停止