记录一下
安装
先把go给安装好
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-xcaddy-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-xcaddy.list
sudo apt update
sudo apt install xcaddy
# 获取最新版本号,其实直接去 GitHub realse 页复制以下就行
# 这里转化为脚本是为了方便自动化
export version=$(curl -s "https://api.github.com/repos/caddyserver/caddy/releases/latest" | jq -r .tag_name)
# 使用 xcaddy 编译
# 使用 xcaddy 编译
# xcaddy build ${version} --output ./caddy_${version} \
xcaddy build v2.7.5 \
--output ./caddy_v2.7.5 \
--with github.com/abiosoft/caddy-exec \
--with github.com/caddy-dns/cloudflare \
--with github.com/caddy-dns/dnspod \
--with github.com/caddy-dns/duckdns \
--with github.com/caddy-dns/gandi \
--with github.com/caddy-dns/route53 \
--with github.com/greenpau/caddy-authorize \
--with github.com/greenpau/caddy-auth-portal \
--with github.com/greenpau/caddy-trace \
--with github.com/hairyhenderson/caddy-teapot-module \
--with github.com/kirsch33/realip \
--with github.com/porech/caddy-maxmind-geolocation \
--with github.com/caddyserver/transform-encoder \
--with github.com/mholt/caddy-webdav
安装并替换
# 安装标准版本 Caddy2
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
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
sudo apt update
sudo apt install caddy
# 替换二进制文件
systemctl stop caddy
rm -f /usr/bin/caddy
mv ./caddy_v2.7.5 /usr/bin/caddy
*****.**** {
root * /data/disk/www/html
encode gzip
php_fastcgi unix//var/run/php/php8.1-fpm.sock
file_server
}
修改/lib/systemd/system/caddy.service
后需要执行sudo systemctl daemon-reload
配置文件还是在/etc/caddy/Caddyfile
遇到的问题
- 过多重定向 原因 开启SSL证书后选择灵活SSL,由于灵活的SSL强制通过未加密的HTTP连接到源Web服务器,然而web服务器只能以https的方式进行访问,结果http就被拒之门外了。
解决方法 对于采用cloudflare提供的CDN加速来说,将灵活ssl切换到完全的SSL。
但是最后是直接把证书移过去解决的QAQ
未知 以及文件读写问题
把php的默认用户组改成了caddy,未知好坏
vim /etc/php/8.1/fpm/pool.d/www.conf
sudo systemctl restart php8.1-fpm
sudo systemctl restart caddy.service
无法写入的原因是caddy的目录但是php-fpm是www-data