← All posts
1 March 2025 · 4 min read

Building Custom Caddy Servers

Helpful but Incomplete

Caddy is built using Go(lang) so to get going we’re going to need Go installed on our server if we are going to be building an extended version of caddy.

First, lets check what version of Go is already installed, if there is one:

If you do have Go installed, you’ll see something like this:

Go
root@caddyserver:~# go version
go version go1.23.5 linux/amd64

If you don’t have Go installed, you’ll see this:

No Go
root@caddyserver:~# go version
-bash: go: command not found

Which means you’ll need to get it installed. Let’s go get Go. Once you know what version you are going to be using, you can install it as follows, or you can just follow the instructions on the Go website.

Go get Go
GO_VERSION=1.23.5

wget https://go.dev/dl/go{GO_VERSION}.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -zxf go{GO_VERSION}.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin

Now, when you run go version you will get a better response

Go
root@caddyserver:~# go version
go version go1.23.5 linux/amd64

Next, we should actually install caddy, this will just make it simpler to make sure all the infrastructure is in place once we come to update caddy with our custom build.

Install caddy
apt install caddy -y
systemctl stop caddy

We are going to stop caddy as soon as we get it in there, we don’t want it running so that we can update it once we have our build.

Next step is to get xcaddy installed so that we can build our custom version

Install caddyx
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-xcaddy-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-xcaddy.list
apt update
apt install xcaddy -y
xcaddy --version

Excellent, we have caddy and xcaddy installed. Now we can make a build of caddy with an additional module. You can find a list of the extra features on the download page. That is the other way to build this out but there are warnings all over the page telling us not to use it, so we will continue with this method. We are going to be building caddy with Bunny DNS for our DNS challenges, because it is awesome.

Build caddy
xcaddy build --with github.com/caddy-dns/bunny

This will build the new version with bunny dns resulting in a new caddy binary being created in whichever directory you called the command from. Now all you have to do is copy the new binary across so that it can used when you start it up

cp ./caddy /usr/bin/
systemctl start caddy

The last piece of the puzzle is to add our Bunny DNS API key into the Caddyfile.

micro /etc/caddy/Caddyfile
# yeah, that's right, I use micro. You can use whichever text editor you like, no judgement.

Update you Caddyfile to include your Bunny DNS API Key

Caddyfile
# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

tls {
        acme_dns bunny XXxxXxXx-xxxx-XXXX-xxxx-XXXX-XXxxXXxxXXxx
}


:80 {
        # Set this path to your site's directory.
        root * /usr/share/caddy

        # Enable the static file server.
        file_server

        # Another common task is to set up a reverse proxy:
        # reverse_proxy localhost:8080

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000
}

I am going to be honest, this isn’t the end to the document but there is enough information in here to be getting on with and will help someone get going. At this point I ran into an issue with the Bunny API and the DNS updates are not working to create the wildcard certs. I am going to be looking into it.