WIUNIX ACADEMY
Set up Caddy with automatic HTTPS, step by step
Page 2 of 2. Review the earlier steps and prerequisites before continuing.
YOUR 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
LET’S BUILD
Verify public HTTPS from another machine
This simple setup needs inbound TCP80/443 through host/provider firewalls and any NAT while preserving SSH. Keep the backend and admin endpoint private. ACME also needs outbound issuer access and persistent writable data.
Caddy can advertise HTTP/3 by default; usable HTTP/3 also requires UDP443 reachability. The basic probes here use TCP. Without UDP443, do not call a successful HTTPS probe an HTTP/3 test.
Use the existing firewall manager. The separate panels only inspect UFW/firewalld; review the active zone and interface before deliberately adding needed HTTP/HTTPS access. Do not flush rules, disable enforcement or install a second manager merely to inspect state.
From another machine, request the actual hostname. Check HTTP redirection and a trusted HTTPS application response separately. Never use an insecure certificate-bypass flag to make this check pass.
A different machine · replace app.example.com
curl -I http://app.example.com/
curl -v https://app.example.com/HTTP/1.1 308 Permanent Redirect
Location: https://app.example.com/
WIUNIX Academy: backend is reachableHTTP redirects to HTTPS on the same hostname. HTTPS passes certificate validation and returns the demonstration text. A browser opens without a certificate warning. Exact headers and protocol can vary.
Inspect existing UFW
Read-only; absence of this firewall manager is not itself an error.
if command -v ufw >/dev/null 2>&1; then sudo ufw status verbose; fiInspect existing firewalld
Read the actual active zone/interface; no rules are added.
if command -v firewall-cmd >/dev/null 2>&1; then
sudo firewall-cmd --state
sudo firewall-cmd --get-active-zones
sudo firewall-cmd --list-all
fiFix the common failure points
Investigate the failing layer first: DNS, public connection, certificate, proxy, then application. A running process alone does not prove remote visitors can reach your site.
The service cannot bind to port 80 or 443
Another process may own the listener. Identify it and decide which service should terminate public HTTP/HTTPS. Preserve existing sites before changing ownership.
sudo ss -lntupCertificate issuance fails
Check public A/AAAA records from outside the server, both firewall layers and any NAT forwarding. Remove an incorrect AAAA record rather than assuming IPv4 success proves IPv6. Inspect journal errors; CAA restrictions can also block issuance. Avoid repeated forced retries that risk CA rate limits.
HTTPS works but returns 502 Bad Gateway
Caddy reached the client but cannot use its backend. Confirm the Python terminal is open, verify the loopback port and test the backend directly. A remote backend needs a separate network and trust design.
curl -v http://127.0.0.1:8080/
sudo journalctl -u caddy -n 50 --no-pagerIt works locally but not from the Internet
Local access does not prove inbound routing. Check public DNS, host/provider firewalls and NAT from another network. If a CDN proxies the hostname, distinguish the CDN path from origin reachability before changing Caddy.
Keep the working setup recoverable
Replace the development backend with a supervised application, retain loopback binding and repeat local/public checks. Loopback is not application authentication.
Caddy stores certificates, CA account keys and renewal state as the service identity. Official Debian/COPR units normally use /var/lib/caddy/.local/share/caddy for data and /var/lib/caddy/.config/caddy for saved configuration. Back up persistent data and Caddyfile securely with ownership/modes; Caddyfile alone is not full recovery.
Keep the packaged caddy identity and unit capabilities for low ports. Do not run Caddy manually as root or set binary capabilities just to bind port80. Review identity, persistent writable storage and security policy before changing paths or the unit.
Maintain DNS, challenge ingress, outbound CA access and persistent data for renewal; monitor expiry, service errors and public application health. Do not force renewal or erase CA state to finish. If adding a CDN or proxy later, trust only its verified ranges.
- Keep the challenge path reachable for certificate renewal.
- Back up configuration and service data securely; restrict private-key access.
- Review package upgrades in a lab before production rollout.
- Monitor the public HTTPS endpoint as well as process health.
Undo the demonstration safely
Confirm the saved Caddyfile is the intended initial copy, restore it and reload only after validation succeeds. This restores configuration, not application data. Keep administrative recovery access while reconciling deliberate DNS/firewall changes.
Stop Python with Ctrl+C in its terminal. The panel removes no certificates, CA accounts, package sources or user data. Package removal or changes to shared SELinux policy are separate reviewed operations, not demonstration cleanup.
Server terminal · confirm this is the intended saved configuration
sudo cp -a /etc/caddy/Caddyfile.academy-before /etc/caddy/Caddyfile
sudo -u caddy -H caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile && sudo systemctl reload caddyThe previous valid configuration serves again. The Python demo is stopped, and intentionally changed DNS/firewall settings have been reconciled.
What you have built
You have a boundary between a public HTTPS entry point and a private application, a repeatable validation/reload workflow, and checks separating certificate problems from backend problems.
Extend the setup according to the application: supervision, protected monitoring, recoverable backups and deliberate trusted-proxy handling. Multiple backends and health checks are a separate design step.
GO TO THE SOURCE
Official references
Each environment states how it was reviewed. A documentation review does not claim a hands-on test of every version.
- Caddy: official installation
- Caddy: reverse proxy
- Caddy: automatic HTTPS
- Caddy: service and reloads
- Caddy: validation commands
- Ubuntu 26.10 release notes
- Upstream RPM packaging and SELinux integration
- Caddy persistent data conventions
- Arch Caddy package
- Arch packaged service
- Arch Caddyfile and restricted admin socket
- Manjaro branch policy