使用XCaddy快速且简单地编译Caddy
官方提供的纯净版Caddy2可能无法满足业务需求,这时就可以使用XCaddy编译自定义Caddy2
1.更新系统及安装依赖
1.更新系统
apt update
apt upgrade -y
2.安装证书依赖
apt install curl vim wget gnupg dpkg apt-transport-https lsb-release ca-certificates
3.安装GO依赖
下载安装包
wget https://go.dev/dl/go1.23.1.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.23.1.linux-amd64.tar.gz
加入环境变量
echo "export PATH=\$PATH:/usr/local/go/bin" >> /etc/profile
source /etc/profile
测试GO是否安装成功
root@make:~# go version
go version go1.23.1 linux/amd64
2.安装XCaddy
1.安装XCaddy源
curl -sSL https://dl.cloudsmith.io/public/caddy/xcaddy/gpg.key | gpg --dearmor > /usr/share/keyrings/xcaddy.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/xcaddy.gpg] https://dl.cloudsmith.io/public/caddy/xcaddy/deb/debian any-version main" > /etc/apt/sources.list.d/xcaddy.list
2.安装XCaddy
apt update
apt install xcaddy
3.编译Caddy2
自行输入你想使用的模块
xcaddy build --with github.com/caddyserver/cache-handler --with github.com/ueffel/caddy-brotli --with github.com/caddyserver/transform-encoder --with github.com/RussellLuo/caddy-ext/ratelimit --with github.com/caddy-dns/cloudflare
接下来按照"使用二进制文件安装Caddy2"的步骤安装编译好的Caddy2即可