Caddy Server v2 Reverse Proxy Setup Guide
Last Updated: 11th May 2023
What is Caddy?
Caddy has a wide range of use cases including:
- Web Server
- Reverse Proxy
- Sidecar Proxy
- Load Balancer
- API Gateway
- Ingress Controller
- System Manager
- Process Supervisor
- Task Scheduler
Today we will be installing and setting up Caddy as a Reverse Proxy. This will be on a Debian 10 system but this will also work with Ubuntu 20.
Install - Official Install Docs: https://caddyserver.com/docs/download
1.
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
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
sudo apt update
sudo apt install caddy
Check status: sudo systemctl status caddy
You should see something similar to this:
● caddy.service - Caddy
Loaded: loaded (/lib/systemd/system/caddy.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2020-11-15 20:00:00 UTC; 2min 35s ago
Docs: https://caddyserver.com/docs/
Main PID: 6969 (caddy)
Tasks: 7 (limit: 1167)
Memory: 15.5M
CGroup: /system.slice/caddy.service
└─4028 /usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
- Now head to your server's IP e.g. http://127.0.0.1
You should see:
Reverse Proxy Setup
- Create
Caddyfile
:nano Caddyfile
Use the following template:
example.com {
reverse_proxy 127.0.0.1:8080
}
Basic Repsond Template:
hello.example.com {
repsond "Hello World!"
}
- Restart Caddy and adopt the new config
caddy reload
HTTPS
Once the new config is loaded, a Let's Encrypt HTTPS certificate is automatically generated for the domain. Just make sure the A record points to the Caddy server!
Cool Fact: If Let's Encrypt is down, Caddy will automatically fall over to obtain a free HTTPS certificate form ZeroSSL.
Additional Settings
- Load Balancing
- Active Health Checks
- Passive Health Checks
- Streaming
- Header Manipulation
- Transport
That's it!
Now grab a coffee ☕️
Our other Caddy Guides: