How Caddy works in Uncloud
Caddy runs as a service in global mode, meaning one Caddy container runs on every machine in your cluster. Each Caddy instance:- Listens on ports 80 (HTTP) and 443 (HTTPS/QUIC)
- Watches the cluster state for services with published ports
- Automatically configures routing rules
- Obtains and manages TLS certificates from Let’s Encrypt
- Routes traffic to containers across the mesh network
/var/lib/uncloud/caddy on each machine.
Deploying Caddy
Deploy Caddy across all machines in your cluster:- Initialize a cluster with
uc machine init(unless you use--no-caddy) - Add a machine with
uc machine add(unless you use--no-caddy)
Deploy to specific machines
Deploy Caddy to only certain machines:Specify a Caddy version
Deploy a specific version of Caddy:caddy:2.9.1).
Caddy commands
View current configuration
Display the current Caddyfile configuration:Custom Caddy configuration
You can add custom global Caddy configuration that gets prepended to the auto-generated config.Create a custom Caddyfile
Create a file namedCaddyfile:
Deploy with custom config
Deploy Caddy with your custom Caddyfile:- Set global Caddy options
- Add custom site blocks
- Configure rate limiting
- Set up custom headers
- Add authentication middleware
How does custom config work?
How does custom config work?
When you provide a custom Caddyfile, Uncloud:
- Reads your Caddyfile content
- Generates configuration for your services with published ports
- Concatenates your custom config + auto-generated config
- Stores the combined config at
/var/lib/uncloud/caddy/Caddyfileon each machine - Caddy containers reload with the new configuration
Automatic TLS certificates
Caddy automatically obtains TLS certificates from Let’s Encrypt for all domains you configure in port mappings.How it works
-
You deploy a service with an HTTPS port:
-
Caddy detects the new service and generates a configuration:
- Caddy requests a TLS certificate from Let’s Encrypt using the ACME HTTP challenge
-
Let’s Encrypt verifies you control the domain by making an HTTP request to
http://app.example.com/.well-known/acme-challenge/TOKEN - Caddy receives the certificate and serves your app over HTTPS
Certificate storage
Certificates are stored in/var/lib/uncloud/caddy/data/caddy/certificates/ on each machine. This directory is bind-mounted into the Caddy container.
Since Caddy runs on multiple machines, each machine independently obtains certificates. Let’s Encrypt rate limits prevent issues, and Caddy intelligently handles certificate renewal.
Certificate renewal
Caddy automatically renews certificates before they expire (typically 30 days before expiration for Let’s Encrypt’s 90-day certificates). No manual intervention required. You can check certificate expiration:Rate limits
Let’s Encrypt has rate limits:- 50 certificates per registered domain per week
- 5 duplicate certificates per week
HTTPS port mapping
Publish container ports as HTTPS:compose.yaml:
Multiple domains
Expose a service on multiple domains:HTTP and HTTPS
Expose both HTTP and HTTPS:Troubleshooting HTTPS issues
Certificate not obtained
If Caddy can’t obtain a certificate, check:-
DNS resolution
Ensure your domain resolves to your machine’s public IP
-
Port 80 reachability
Let’s Encrypt needs to reach port 80 for the HTTP challenge:
-
Firewall rules
Ensure ports 80 and 443 are open on your machine:
-
Caddy logs
Check Caddy container logs for errors:
Rate limit errors
If you see errors about rate limits:Certificate mismatch
If you see certificate warnings in your browser:- Check that DNS points to the correct machine
- Clear your browser cache
-
Verify Caddy obtained the certificate:
Look for your domain in the configuration
-
Check certificate files:
Caddy container not starting
If the Caddy container fails to start:-
Check for port conflicts
-
Verify host path exists
-
Check Caddy logs
-
Inspect service state
Advanced configuration
Custom error pages
Add custom error pages in your Caddyfile:Rate limiting
Limit requests per IP:Basic authentication
Protect a site with basic auth:Path-based routing
Route different paths to different services:Caddy service details
The Caddy service deployed by Uncloud has these characteristics:- Service name:
caddy - Mode: Global (one container per machine)
- Image:
caddy:2.X.X(latest stable) - Ports:
80/tcp- HTTP443/tcp- HTTPS443/udp- HTTP/3 (QUIC)
- Volumes:
/var/lib/uncloud/caddy→/configand/data(TLS certificates and config)/run/uncloud/caddy→/run/caddy(Unix socket for admin API)
- Command:
caddy run -c /config/Caddyfile - Environment:
CADDY_ADMIN=unix//run/caddy/admin.sock
Caddy command reference
| Command | Description |
|---|---|
uc caddy deploy | Deploy or upgrade Caddy across machines |
uc caddy deploy --image IMAGE | Deploy a specific Caddy version |
uc caddy deploy --caddyfile PATH | Deploy with custom Caddyfile |
uc caddy deploy --machine MACHINE | Deploy only to specific machines |
uc caddy config | View current Caddyfile configuration |
uc caddy config --machine MACHINE | View config from a specific machine |
uc caddy config --no-color | View config without syntax highlighting |
Next steps
DNS Management
Set up custom domains and DNS records
Monitoring
Monitor service health and logs
