Caddy
Caddy 入门
创建 Caddyfile
localhost {
respond "Hello, world!"
}
localhost:2016 {
respond "Goodbye, world!"
}
localhost:2017 {
root * /home/me/mysite
file_server
}
localhost:2018 {
reverse_proxy 127.0.0.1:9000
}
在当前目录运行 caddy run
后台运行
caddy startcaddy stop
本地文件
caddy file-server --listen :2015 --root ~/mysite
反向代理
caddy reverse-proxy --from :2016 --to 127.0.0.1:9000
HTTPS
只要有域名就可以默认 HTTPS
Caddy 高级
通配符 DNS
Automatic HTTPS — Caddy Documentation > Common Caddyfile Patterns — Caddy Documentation > Build from source — Caddy Documentation > Setup Caddy as a reverse proxy on NixOS (Part 3: Caddy) | Ming Di Leom's Blog
*.example.com {
tls {
dns <provider_name> [<params...>]
}
@foo host foo.example.com
handle @foo {
respond "Foo!"
}
@bar host bar.example.com
handle @bar {
respond "Bar!"
}
# Fallback for otherwise unhandled domains
handle {
abort
}
}
自定义 Caddy
How to use DNS provider modules in Caddy 2 - Wiki - Caddy Community > Download Caddy
默认的 Caddy 不能使用其它的 providers,需要自行用 xcaddy 编译,或者在选择对应的模组下载,然后替换。