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.

Rocky Linux 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

Use the upstream-endorsed @caddy/caddy COPR, not an unrelated COPR or an automatic switch to another distribution build. Review its trust prompt and package source in the transaction. RHEL-family uses dnf-plugins-core; Fedora uses dnf5-plugins. Existing curl-minimal is not forcibly replaced.

Install policycoreutils-python-utils before Caddy so the reviewed upstream RPM can apply SELinux labels. Its script uses httpd_exec_t for /usr/bin/caddy, httpd_config_t for /etc/caddy and httpd_var_lib_t for /var/lib/caddy, and enables httpd_can_network_connect for ACME/proxy traffic. That permission is shared by the httpd domain: use the dedicated fresh VM assumed here.

This package does not start the service automatically. Inspect file labels, boolean and actual process domain after explicit startup. Keep SELinux enforcing; if the installed domain/package differs or denials remain, inspect its actual policy rather than applying an unrelated boolean or recursively relabelling paths.

Bash

Server terminal · sudo access required

(
set -eu
sudo dnf install dnf-plugins-core python3 policycoreutils-python-utils iproute
if ! command -v curl >/dev/null 2>&1; then sudo dnf install curl; fi
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 dnf copr enable @caddy/caddy
sudo dnf install caddy
caddy version
rpm -q caddy
getent passwd caddy
sudo ls -Zd /usr/bin/caddy /etc/caddy /var/lib/caddy
getsebool httpd_can_network_connect
sudo systemctl enable --now caddy
systemctl is-active caddy
sudo ps -eZ | grep '[c]addy'
systemctl show caddy -p User -p Group -p FragmentPath -p AmbientCapabilities
)
How do I know it worked?

The intended COPR package, labels and actual process domain are inspected; caddy.service is enabled and active.

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 ↗