108.4. caddy-2.11.4
Web server with built-in TLS certificate management
| Version | 2.11.4, release 1 |
| Shelf | servers — Daemons that serve other machines: remote shell, web, mail, XMPP, IRC, CalDAV/CardDAV, SMB and DLNA |
| Phase | 41_system (System), 942 of 1047 in build order |
| Licence | Apache-2.0 |
| Homepage | https://caddyserver.com/ |
| Build time | 0.9 SBU |
| Installed size | 56.5 MiB in 30 files |
| Recipe | ports/core/servers/caddy/kpkgbuild |
About
Caddy is a web server and reverse proxy, written in Go, that manages its own TLS certificates. It builds as one static binary with its standard modules compiled in. The shipped Caddyfile has one site: port 8443, which proxies to kiwix-tools’ kiwix-serve, the offline library, expected on localhost:8080, and so serves it over HTTPS to any browser on the LAN. There is no service script; Caddy is started by hand with caddy run --config /etc/caddy/Caddyfile. Other machines reach it once the firewall’s caddy name is on (see Syncing and serving on the network). That name opens TCP 8443 and nothing else, so a site moved to another port needs a rule of its own in /etc/nftables.d.
Why it is in KDOS
The comment above it in script/phases/41_system/packages.d/servers.txt:
Caddy's default config asks Let's Encrypt and fails at every start, so the shipped Caddyfile uses
tls internal— its own local CA, needing nothing outside this machine.
Sources
caddy-2.11.4.tar.gz(824.3 KiB)
sha2562c3d02078286a6282cdb4d1d8744077788d556659dac0b64d8ed5886a7e5aeb9
upstream: https://github.com/caddyserver/caddy/archive/refs/tags/v2.11.4.tar.gz
archive copy: sources-4/servers--caddy-2.11.4.tar.gzcaddy-vendor-2.11.4.tar.xz(6.2 MiB)
sha2562fb48e35bde7c5e5ec7e49a50689189be3744e275e70b468fabe64a4bf800616
a vendor bundle: the dependencies upstream’s own tool would download, packed once
archive copy: sources-4/servers--caddy-vendor-2.11.4.tar.xz
Dependencies
Depends on: go.
Required by: no port names it.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install caddy'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/servers/caddy.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/servers/caddy
echo '2c3d02078286a6282cdb4d1d8744077788d556659dac0b64d8ed5886a7e5aeb9 caddy-2.11.4.tar.gz' | sha256sum -c -
echo '2fb48e35bde7c5e5ec7e49a50689189be3744e275e70b468fabe64a4bf800616 caddy-vendor-2.11.4.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/caddy
SRC=$SRC_ROOT/caddy-2.11.4
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf caddy-2.11.4.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz
export CGO_ENABLED=0
go build -mod=vendor -ldflags "-s -w" -o caddy ./cmd/caddy
install -Dm755 caddy $PKG/usr/bin/caddy
./caddy manpage --directory $PKG/usr/share/man/man8
install -Dm644 /dev/stdin $PKG/etc/caddy/Caddyfile <<'CFG'
# `tls internal` is the whole point of this file. Caddy's default is to ask
# Let's Encrypt for a certificate, which on a machine with no route to the
# internet fails at every start — so the server that was supposed to serve the
# offline corpus is the one thing that does not come up. `internal` issues from
# Caddy's own local CA; trust its root once and every host below is https.
{
auto_https disable_redirects
local_certs
}
# The corpus, served to any browser on the LAN with no client install, once
# `kdos-power firewall caddy on` has opened 8443 — the firewall's `caddy` is
# this port, so moving it means another rule of your own in /etc/nftables.d.
# kiwix-serve is expected on 8080; change the port, not the shape.
:8443 {
tls internal
reverse_proxy localhost:8080
}
CFG
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/caddy, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf caddy-2.11.4-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/caddy, and runs the triggers its paths call for.
Contents
Installed programs: caddy.
Installed directories: /etc/caddy, /usr/share/licenses/caddy.
Notes
For a site with a public domain name, Caddy’s default is to get its certificate from a public ACME CA, Let’s Encrypt first. On a machine with no route to the internet every such attempt fails and the site has no certificate to serve, so the shipped Caddyfile uses local_certs and tls internal: the certificates come from Caddy’s own local CA, which needs nothing outside the machine, and a browser’s warning is answered by trusting that one root rather than by turning TLS off. auto_https disable_redirects turns off Caddy’s automatic HTTP-to-HTTPS redirects. A private CA shared by several machines is step-ca’s job; Caddy can renew against it over ACME.
The Go modules come from the vendor bundle, caddy-vendor-<version>.tar.xz, which ports/fetch makes with go mod vendor because the recipe says vendoring = go; build.sh unpacks it and builds with -mod=vendor, offline. See Vendoring.
The manual pages are written by the binary just built: caddy manpage --directory generates one page for each Caddy command, in section 8.