我可以有一个有多个域的服务器,使用这样的Caddyfile (+ https with letsencrypt):
site1.com {
reverse_proxy localhost:3001
}
site2.com {
reverse_proxy localhost:3002
}
site3.com {
reverse_proxy localhost:3003
}但是我想在没有Caddyfile的情况下运行Caddyfile,并且我想通过admin 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添加反向代理?我使用的是Cady2.0版
发布于 2021-05-20 12:35:30
你不需要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}]}}}}}https://stackoverflow.com/questions/62556632
复制相似问题