Set up local HTTPS with Caddy as a reverse proxy for multiple Docker projects, using trusted certificates on Windows.
This guide is visually formatted for GitHub markdown and step-by-step for easy reference!
caddy/
├── compose.yml
└── conf/
└── Caddyfile
- Run Notepad as Administrator
- Open:
C:\Windows\System32\drivers\etc\hosts
- Add:
127.0.0.1 project1.local 127.0.0.1 project2.local
- Save and close.
docker run -d -p 8001:80 --name project1-whoami traefik/whoami
docker run -d -p 8002:80 --name project2-whoami traefik/whoami
- Port 8001:
project1-whoami
- Port 8002:
project2-whoami
services:
caddy:
image: caddy:2.8.4
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- ./conf:/etc/caddy
- caddy_data:/data
- caddy_config:/config
volumes:
caddy_data:
caddy_config:
project1.local {
reverse_proxy host.docker.internal:8001
tls internal
}
project2.local {
reverse_proxy host.docker.internal:8002
tls internal
}
ℹ️
host.docker.internal
lets Caddy (in Docker) reach containers running on your host machine.
Navigate to your caddy
directory and run:
docker compose up -d
docker ps
Look for the container named caddy
(use that name below).
docker cp caddy:/data/caddy/pki/authorities/local/root.crt "$env:TEMP\root.crt"
(Replace caddy
with your actual container name if different.)
certutil -addstore -f "ROOT" "$env:TEMP\root.crt"
Or, double-click the file and follow the Windows Certificate Import Wizard.
💡 You may need to import manually into browsers like Firefox (Settings → Privacy & Security → Certificates → Authorities → Import).
If you edit conf/Caddyfile
, reload Caddy with:
docker exec -w /etc/caddy caddy-caddy-1 caddy reload
Note:
No need to restart the container. This command tells Caddy to reload its config instantly.
You should see the whoami page for each, using HTTPS with no browser warnings!
Easily add a new site using WSL2/Linux or Windows PowerShell:
Environment | Script | How to Run |
---|---|---|
WSL2 / Linux | add-caddy-site.sh |
./add-caddy-site.sh in your terminal |
Windows | add-caddy-site.ps1 |
Run from PowerShell as Administrator:.\add-caddy-site.ps1 |
Both scripts:
- Prompt you for container, domain, and port.
- Update the Caddyfile inside the container.
- Format and reload Caddy.
- On Windows, your hosts file is updated automatically.
On WSL2/Linux, don’t forget to add your domain toC:\Windows\System32\drivers\etc\hosts
:
127.0.0.1 yoursite.local
Step | Action | Command/Location |
---|---|---|
1 | Add domains to hosts file | C:\Windows\System32\drivers\etc\hosts |
2 | Start whoami containers | docker run ... |
3 | Set up Caddy/Compose | compose.yml , conf/Caddyfile |
4 | Start Caddy container | docker compose up -d |
5 | Copy/trust CA cert | docker cp ... , certutil -addstore ... |
6 | Test in browser | https://project1.local, https://project2.local |
- If you get SSL warnings, make sure you imported the CA cert into both Windows and your browser's trusted authorities.
- To add more projects, repeat steps for additional ports and domains!
- For static sites, mount a
site
folder and useroot * /srv
in your Caddyfile.
MIT
Enjoy your secure, local multi-project development setup! 🚦