系统:debian12
准备工作
假设1234.com是用户访问的域名,再找一个域名,例如 1234.kkk.eu.org
1234.kkk.eu.org 绑定到源站(注意:1234.com也要绑定到源站)
1234.kkk.eu.org 解析到源服务器 IP 地址,开启 CDN(小云朵),设置为灵活模式
安装caddy
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
chmod o+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg
chmod o+r /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
检测是否安装成功
caddy -v
配置修改
nano /etc/caddy/Caddyfile
反代配置如下:
(common) {
tls {
protocols tls1.2 tls1.3
}
header {
-Via
-Alt-Svc
-Server
}
}
(proxy) {
header_up Host {upstream_hostport}
header_up X-Real-IP {remote}
}
1234.com {
redir https://www.1234.com{uri} permanent
}
www.1234.com {
import common
reverse_proxy https://1234.kkk.eu.org {
import proxy
}
}
重启生效
systemctl restart caddy
将 Caddy 添加到开机自启
systemctl enable caddy
查看 Caddy2 运行状态
systemctl status caddy
格式规范的警告,使用以下命令修复
caddy fmt --overwrite /etc/caddy/Caddyfile
卸载caddy
systemctl stop caddy
apt purge caddy
rm -rf /etc/caddy /var/lib/caddy /var/log/caddy