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.
Make this guide yoursYOUR SYSTEM. YOUR STEPS.
Where are you working?
Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.
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.
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.
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.
Server terminal · ordinary user
cat /etc/os-release
uname -m
ps -p 1 -o comm=
command -v systemctlThe 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.
LET’S BUILD
Install the Caddy package
Use the signed distribution caddy package. The upstream installation command performs a full pacman system upgrade; read the transaction and distribution update notices first. This rolling path is reviewed for x86_64. Manjaro must use its own Stable repositories, not added Arch repositories.
The package creates the caddy account and a modified caddy.service, but does not enable it automatically. Its XDG_DATA_HOME=/var/lib, ProtectHome and restricted writable paths differ from the Debian/COPR unit. Caddy data is under /var/lib/caddy rather than the nested Debian/COPR default.
Start the packaged service explicitly after checking listener ownership. Preserve its restricted Unix admin socket under /run/caddy in the later configuration. Caddy reaches Python over loopback HTTP and does not need to read files in the demo home directory.
Server terminal · sudo access required
(
set -eu
test "$(uname -m)" = x86_64
sudo pacman -Syu --needed caddy python curl 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
caddy version
pacman -Q caddy python curl
getent passwd caddy
sudo stat -c '%a %U:%G %n' /var/lib/caddy /run/caddy
sudo systemctl enable --now caddy
systemctl is-active caddy
systemctl show caddy -p User -p Group -p FragmentPath -p AmbientCapabilities -p ProtectHome -p ReadWritePaths
)The signed distribution package/account/directories are present and the service is explicitly enabled.
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.
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
)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.
curl --fail --silent --show-error --max-time 5 http://127.0.0.1:8080/
sudo ss -lntp 'sport = :8080'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.
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
)An exclusive initial backup exists and the fresh-install Caddyfile is open for editing.
LET’S BUILD
Write the reverse-proxy configuration
Replace the fresh package HTTP welcome site while retaining its restricted Unix admin endpoint and conf.d import, as shown. Stop if other real sites/settings already exist.
The domain enables automatic HTTPS and loopback reverse proxying. The backend is reached over HTTP, so ProtectHome can stay enabled. Protect access-log retention.
File contents in the editor opened in the preceding step
{
admin unix//run/caddy/admin.socket
}
app.example.com {
reverse_proxy 127.0.0.1:8080
log
}
import /etc/caddy/conf.d/*The fresh-install file contains the actual hostname and loopback backend; the packaged HTTP welcome site no longer substitutes for this named site.
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.
First server terminal · sudo for validation, reload and logs
sudo -u caddy -H env XDG_DATA_HOME=/var/lib XDG_CONFIG_HOME=/etc 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-pagerValid configuration
activeValidation succeeds, the service is active, and no unresolved configuration or listener error appears. The displayed output is illustrative; timestamps and extra log lines differ.