IT engineering workspace with server equipment and a teaching board about Caddy reverse proxy and automatic HTTPS

WIUNIX ACADEMY

Set up Caddy with automatic HTTPS, step by step

Install the right Caddy package for your Linux server, proxy a private loopback application and verify certificate trust, service access and a recoverable configuration.

Intermediate25 min readUpdated
Make this guide yours

YOUR SYSTEM. YOUR STEPS.

Where are you working?

Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.

Ubuntu 26.10Reviewed against official documentation ·

USE YOUR OWN VALUES

Configure this tutorial

Set the example values for your environment; related explanations and copy panels update together. Never enter passwords, private keys or tokens. Values stay in this tab and are not sent to the server or share links. Check actual DNS, certificates and network policy before running commands.

Different IP addresses, domains or ports? Open the settings below, change the values and select “Apply to tutorial”, then copy the updated commands.

Set values for my environment3 editable values

THE OUTCOME

What will you have at the end?

A Caddy reverse proxy serving your own hostname over automatically managed HTTPS, forwarding to a private loopback backend. Learn to validate, reload, inspect failures and restore the previous configuration.

01Your visitorA real hostname over HTTPS
02CaddyCertificates and public ingress
03Your application127.0.0.1:8080 · private
Supported operating systems and versions

A fresh dedicated systemd VM walkthrough. Ubuntu/Debian use the upstream-endorsed Cloudsmith Stable package source; RHEL-family/Fedora use the upstream @caddy/caddy COPR; Arch/Manjaro use their distribution package and modified unit. OS paths are documented, not all-OS installation tests. Windows, macOS, WSL and non-systemd containers are outside scope.

Before you begin

  • A fresh dedicated Linux VM with a selected reviewed release, systemd, Bash/sudo and separate recovery access. This is not an automatic migration of existing websites.
  • An owned public hostname, DNS administration and host/provider firewall or NAT access for TCP80/443. Publish AAAA only when that IPv6 path reaches the same server.
  • Unoccupied web ports and trusted local operators. Keep the demonstration backend and admin endpoint private. DNS propagation and certificate issuance may take longer than the reading time.
01

LET’S BUILD

Check the server and plan the hostname

Use a fresh dedicated lab VM so other web services and configurations are not taken over. This is a systemd-managed package installation, not a guide for every Linux-like terminal.

Compare ID and VERSION_ID with the selected environment and confirm PID1 is systemd. The architecture must have the chosen package available; Arch/Manjaro paths here are reviewed for x86_64.

Point the owned hostname A record to this server. Publish AAAA only when that IPv6 path reaches the same server; a broken IPv6 route can disrupt issuance or some clients despite IPv4 success.

Bash

Server terminal · ordinary user

cat /etc/os-release
uname -m
ps -p 1 -o comm=
command -v systemctl
How do I know it worked?

The distribution and version match your selection, the CPU architecture has a package available, and PID 1 is systemd. You control a real hostname and its DNS records.

02

LET’S BUILD

Install the Caddy package

For Ubuntu/Debian, use the upstream-endorsed Cloudsmith Stable source. Store its signing key in a dedicated keyring referenced by that repository. Python supports the disposable backend; iproute2 supplies listener inspection.

Read each package transaction. The Debian package starts Caddy automatically, so the panel refuses occupied web ports before installing Caddy. Do not stop another service to force this new-install walkthrough to proceed.

The panel refuses existing repository/key files and uses a private temporary directory for public repository downloads. Manage an existing installation through its own workflow. Record the installed version; Stable moves forward. The temporary public review-file location is printed at the end.

Bash

Server terminal · sudo access required

(
set -eu
sudo apt update
sudo apt install debian-keyring debian-archive-keyring apt-transport-https curl gnupg python3 iproute2
listeners=$(sudo ss -H -lntup '( sport = :80 or sport = :443 )')
if test -n "$listeners"; then
  printf '%s\n' 'A web port is already in use; inspect listener ownership before starting Caddy.'
  exit 1
fi
sudo test ! -e /usr/share/keyrings/caddy-stable-archive-keyring.gpg
sudo test ! -L /usr/share/keyrings/caddy-stable-archive-keyring.gpg
sudo test ! -e /etc/apt/sources.list.d/caddy-stable.list
sudo test ! -L /etc/apt/sources.list.d/caddy-stable.list
repo_tmp=$(mktemp -d)
curl --fail --silent --show-error --location https://dl.cloudsmith.io/public/caddy/stable/gpg.key -o "$repo_tmp/key.asc"
gpg --dearmor --output "$repo_tmp/key.gpg" "$repo_tmp/key.asc"
curl --fail --silent --show-error --location https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt -o "$repo_tmp/caddy.list"
sudo install -m 0644 "$repo_tmp/key.gpg" /usr/share/keyrings/caddy-stable-archive-keyring.gpg
sudo install -m 0644 "$repo_tmp/caddy.list" /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
caddy version
systemctl is-active caddy
getent passwd caddy
systemctl show caddy -p User -p Group -p FragmentPath -p AmbientCapabilities
printf 'Public repository review files: %s\n' "$repo_tmp"
)
How do I know it worked?

The package is installed, caddy prints its version and the service is active under its packaged caddy account. Public certificate/application checks still follow.

03

LET’S BUILD

Start a private demonstration backend

In a second terminal, create a new dedicated directory and start a disposable Python HTTP server bound only to127.0.0.1. An existing path is refused rather than overwriting index.html. Caddy is the public ingress.

Leave this terminal running. Caddy reaches Python over loopback HTTP, not by reading the home directory. Replace the development server with your supervised application before real use.

Bash

Second server terminal · ordinary user · leave running

(
set -eu
demo_path=~/academy-caddy-demo
test ! -e "$demo_path"
test ! -L "$demo_path"
mkdir -m 0700 -- "$demo_path"
cd -- "$demo_path"
printf '%s\n' 'WIUNIX Academy: backend is reachable' > index.html
python3 -m http.server 8080 --bind 127.0.0.1
)
How do I know it worked?

Python listens on127.0.0.1:8080. Use the separate first-terminal check below and expect the WIUNIX Academy message.

Check from the first terminal

After Python starts in the second terminal, expect the sample response and a loopback-only listener from this first-terminal check.

Bash
curl --fail --silent --show-error --max-time 5 http://127.0.0.1:8080/
sudo ss -lntp 'sport = :8080'
04

LET’S BUILD

Back up and open the Caddyfile

Back up the packaged Caddyfile before editing. The fixed backup path is exclusive: an existing backup stops this panel instead of being overwritten.

On this fresh VM, replace the packaged welcome-site example with the next configuration using sudoedit. If real sites unexpectedly exist in this file, stop this replacement walkthrough and integrate changes through their owner instead.

bash

Server terminal; sudo required

(
set -eu
sudo test ! -e /etc/caddy/Caddyfile.academy-before
sudo test ! -L /etc/caddy/Caddyfile.academy-before
sudo cp -a --no-clobber /etc/caddy/Caddyfile /etc/caddy/Caddyfile.academy-before
sudoedit /etc/caddy/Caddyfile
)
How do I know it worked?

An exclusive initial backup exists and the fresh-install Caddyfile is open for editing.

05

LET’S BUILD

Write the reverse-proxy configuration

Use the editor already opened and replace the fresh package welcome-site configuration. Save the next panel as file contents, never shell commands; the hostname must be your actual domain.

The hostname activates automatic HTTPS; reverse_proxy forwards only to the loopback backend. The log directive enables access logs captured by this packaged service journal. Restrict log access/retention and keep sensitive data out of URLs.

This setup is one hostname and one local backend. Existing sites, a CDN or another upstream proxy require their own reviewed integration.

Caddyfile · /etc/caddy/Caddyfile

File contents in the editor opened in the preceding step

app.example.com {
    reverse_proxy 127.0.0.1:8080
    log
}
How do I know it worked?

The fresh-install file contains the actual hostname and loopback backend; the packaged HTTP welcome site no longer substitutes for this named site.

06

LET’S BUILD

Validate, then reload

Validate the exact file as the caddy account before loading it. This catches read/provisioning errors but does not reproduce every systemd sandbox or SELinux constraint of the running service.

Reload only after successful validation, then inspect service state and recent logs. Correct the actual error instead of repeatedly restarting. An active process is not proof of public certificate or application success.

Bash

First server terminal · sudo for validation, reload and logs

sudo -u caddy -H caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile && sudo systemctl reload caddy
systemctl is-active caddy
sudo journalctl -u caddy --since '5 minutes ago' --no-pager
EXAMPLE OUTPUT
Valid configuration
active
How do I know it worked?

Validation succeeds, the service is active, and no unresolved configuration or listener error appears. The displayed output is illustrative; timestamps and extra log lines differ.

Explore all tutorials ↗