使用XCaddy编译Caddy2

官方提供的纯净版Caddy2可能无法满足业务需求,这时就可以使用XCaddy编译自定义Caddy2

更新系统及安装依赖

更新系统

apt update
apt upgrade -y

安装证书依赖

apt install curl vim wget gnupg dpkg apt-transport-https lsb-release ca-certificates

安装GO依赖

下载安装包

wget https://go.dev/dl/go1.23.2.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.23.2.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.2 linux/amd64

安装XCaddy

安装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

安装XCaddy

apt update
apt install xcaddy

编译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