下载caddy_windows_amd64.exe 文件并改名为caddy.exe即可使用.
caddy run 运行程序
caddy start 后台运行程序
caddy stop 结束程序
=========Json配置文件(API模式)===========
默认情况下 caddy 的配置为空,新建配置文件并上传
caddy.json文件内容
{"apps":{"http":{"servers":{"hello":{"listen":[":2015"],"routes":[{"handle":[{"handler":"static_response","body":"Hello, world!"}]}]},"bye":{"listen":[":2016"],"routes":[{"handle":[{"handler":"static_response","body":"Goodbye, world!"}]}]}}}}}
上传配置文件
curl localhost:2019/load \ -X POST \ -H "Content-Type: application/json" \ -d @caddy.json
curl localhost:2019/config 查看配置文件
curl localhost:2015 查看网页输出内容是否为Hello,World!
==============caddyfile配置文件(CLI模式)================
在caddy.exe目录下,新建Caddyfile文件(无后缀名)
localhost {respond "Hello,world!"}
localhost:2016 {respond "Goodbye,world!"}
caddy adapt 将Caddyfile转换为Caddy的本机JSON配置
--config 指定配置文件路径
--adapter 指定配置文件名
--resume 指定为默认配置
--reload 重新加载配置
=====================静态文件服务器==============================
caddy file-server --listen :2015 启动文件服务器
--browse 显示文件列表
--root 指定站点根目录
使用caddyfile配置文件
localhost:2015 root * /home/me/mysite file_server browse
========================反向代理===============
caddy reverse-proxy --form :2016 --to 127.0.0.1:9000 启动反向代理访问站点
使用caddyfile配置文件
localhost:2016 reverse_proxy 127.0.0.1:9000
====================Https===============
example.com 将域的 A/AAAA 记录设置为指向您的服务器
请确保您的服务器可通过端口 80 和 443 从外部从公共接口
使用caddyfile配置文件
example.com respond "Hello, privacy!"
如果您只需要通过 HTTPS 提供静态文件
caddy file-server --domain example.com
如果您只需要一个通过HTTPS的简单反向代理
caddy reverse-proxy --from example.com --to localhost:9000
Json配置,生产就绪型自动https
{"apps":{"http":{"servers":{"hello":{"listen":[":443"],"routes":[{"match":[{"host":["example.com"]}],"handle":[{"handler":"static_response","body":"Hello, privacy!"}]}]}}}}}