This article applies to both Debian 10 Buster and Ubuntu 20.04 Focal.
xcaddy is the official Caddy tool for custom compiling Caddy, it can help us compile Caddy to meet our needs quickly.
Install xcaddy
Let’s follow the official installation method and first, install some necessary packages.
Then follow the official tutorial to install Go.
Then add go to the system environment variables.
|
|
Then add Caddy’s GPG public key and apt source.
|
|
Then you can install xcaddy after updating your system.
After rebooting and opening SSH, check the version of go and xcaddy.
Custom Compilation Caddy
We can choose some modules we like, such as Cache Module and Brotli Compression Module.
After some compilation time, we can see a binary file named caddy
in the current directory, which is our custom compiled Caddy.
Custom Caddy and System Caddy coexist
If we want to customize Caddy to coexist with the system Caddy, we can use the official tutorial.
First, follow our tutorial Install Caddy, and after installation, stop the Caddy service first:
|
|
Then use the dpkg-divert
command to move the system Caddy binary to /usr/bin/caddy.default
and make a soft link to it.
|
|
Then move our own compiled Caddy binaries to /usr/bin/caddy.custom
.
|
|
Then set the priority so that our custom Caddy starts first.
At this point we can see that the default /usr/bin/caddy
is now our custom Caddy.
We can also use the update-alternatives --config caddy
command to switch between the system-installed Caddy and the custom Caddy.
|
|
We can see that the default Caddy binary is our custom one, you can modify and switch the default Caddy version by entering 0 (automatically according to priority) 1 (manually switch custom Caddy) or 2 (use system default Caddy).