Once the website container (then an Astro app in Podman) answered on 127.0.0.1:4321, I still needed HTTPS and a single canonical hostname. I picked Caddy over nginx for one reason: its built-in ACME client means I never touch certbot timers or renewal cron jobs.
Install Caddy
Caddy isn't in the default Debian repositories, so I added Cloudsmith's stable channel:
sudo apt update
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list >/dev/null
sudo apt update
sudo apt install -y caddy
Reverse proxy and canonical host
Two DNS names pointed at the VPS, adrian-altner.de and www.adrian-altner.de. I wanted exactly one of them to be public, with the other answering with a 301. Caddy's site blocks do both jobs at once, TLS and the redirect, with no extra configuration:
# /etc/caddy/Caddyfile
www.adrian-altner.de {
redir https://adrian-altner.de{uri} permanent
}
adrian-altner.de {
encode zstd gzip
reverse_proxy 127.0.0.1:4321
}
On first start, Caddy fetches Let's Encrypt certificates for both hostnames, serves adrian-altner.de through the reverse proxy and answers www.adrian-altner.de with a permanent redirect.
Validate and reload
sudo caddy validate --config /etc/caddy/Caddyfile
sudo systemctl restart caddy
sudo systemctl enable caddy
sudo systemctl status caddy --no-pager
A formatting warning from validate is harmless. caddy fmt cleans it up in place:
sudo caddy fmt --overwrite /etc/caddy/Caddyfile
Verify the result
curl -I http://adrian-altner.de
curl -I https://adrian-altner.de
curl -I https://www.adrian-altner.de
What I was looking for:
- HTTP redirects to HTTPS (Caddy does this on its own once TLS is in place).
wwwreturns a 301 to the bare domain.- The certificate is trusted and issued by Let's Encrypt.
Close the app port
With Caddy as the only public entry point, there's no reason for port 4321 to be reachable from outside. Binding it to localhost in the compose file closes that door:
ports:
- '127.0.0.1:4321:4321'
Now the app only listens on the loopback interface, and Caddy alone handles 80 and 443.
Takeaways
- Bind the app container to
127.0.0.1as soon as a proxy sits in front of it. Exposing it publicly gains nothing. - One canonical hostname, with the other redirecting, avoids duplicate content in search engines later.
- Topic
-
- Self-Hosting Running services on a server you control instead of using a provider's hosted version, with the upkeep that comes with it.
- Basis for
-
- Security Headers in Caddy A strict Content Security Policy, HSTS and no-referrer in a Caddy site block, checked with Webbkoll, securityheaders.com and the Mozilla Observatory.
- Uses
- Mentioned in
-
- Astro SSR with Podman: From Local Setup to VPS Astro with the Node standalone adapter in a two-stage Podman container, run locally with the same compose file that later goes to the VPS.
- Deploying Astro SSR to a VPS with Podman Moving the Astro SSR container to a fresh Debian VPS: Podman from the distro packages, a read-only deploy key and the same compose file.
- Keeping a Compose Stack Running After a Reboot A systemd unit that starts a Podman compose stack on boot, so a website comes back by itself after the VPS restarts.
- My Old Astro Website My old site at adrian-altner.de: Astro with the Node adapter, typed content collections, IndieWeb features and photos as files with JSON sidecars.
- Updating the Website Repository on a VPS A repeatable update flow on the VPS: check the working tree, pull with --ff-only, rebuild with podman-compose, verify, roll back, all in one script.
- Mentioned
-
- Astro Tool for building websites from content such as Markdown. Ships plain HTML by default and only loads JavaScript where it is needed.
- Tags