Noonisy
Caddy 相关
2025-05-02
阅读:65

Caddy 相关


对于 ubuntu,使用命令安装
sudo apt update
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
# 添加 Caddy 的 GPG 密钥
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
# 添加 Caddy 的 APT 仓库
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install -y caddy

sudo systemctl status caddy
sudo systemctl start caddy
sudo systemctl enable caddy
sudo systemctl reload caddy
编辑配置文件
sudo vim /etc/caddy/Caddyfile

a.example.com {
    # 将所有到 a.example.com 的请求反向代理到本地的 7522 端口
    reverse_proxy localhost:7522

    # Caddy 会自动为 a.example.com 获取和续订 Let's Encrypt 证书
    # 并自动处理 HTTP 到 HTTPS 的重定向

    # 可选:添加一些常见的代理头信息,后端服务可能需要它们
    # header_up Host {http.request.host}
    # header_up X-Real-IP {http.request.remote}
    # header_up X-Forwarded-For {http.request.remote}
    # header_up X-Forwarded-Proto {scheme}

    # 可选:启用访问日志 (默认情况下 Caddy 会有结构化日志)
    # log {
    #    output file /var/log/caddy/a.example.com.access.log
    #    format json # 或者使用 common_log 等其他格式
    # }
}
caddy 的 ssl 证书
cd /var/lib/caddy/.local/share/caddy/certificates/
# 路径下/<ACME_ISSUER>/<YOUR_DOMAIN_COM>/ 存在证书文件 crt 和私钥文件 key
其他操作
# 格式化 Caddyfile: 这有助于保持文件整洁并捕获一些基本语法错误。
caddy fmt --overwrite /etc/caddy/Caddyfile
# 验证 Caddyfile: 检查配置文件语法是否正确。
caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile
# 重新加载 Caddy 配置
sudo systemctl reload caddy
# 日志
sudo journalctl -u caddy -n 100 --no-pager -f
最后编辑于:2025 年 05 月 20 日 02:13
邮箱格式错误
网址请用http://或https://开头