Caddy Reverse Proxy
Uncloud uses Caddy as a reverse proxy to expose your services to the internet. Caddy automatically handles TLS certificate provisioning, renewal, and HTTPS redirection.How It Works
When you initialize a cluster or add a machine, Uncloud:- Deploys Caddy in global mode across all machines
- Configures Caddy to watch cluster state for services with published ports
- Automatically provisions TLS certificates for exposed domains
- Routes incoming HTTP/HTTPS traffic to backend containers
Caddy runs as a container on each machine, making every machine capable of handling ingress traffic.
Publishing Services
You can expose services using the-p/--publish flag or in your compose file.
Using the CLI
Using Docker Compose
myapp.example.com.
If you don’t specify a protocol, Uncloud defaults to HTTPS for security.
Automatic HTTPS with Let’s Encrypt
Caddy automatically obtains and renews TLS certificates from Let’s Encrypt for all exposed domains.Certificate Provisioning
When you publish a service with a custom domain:- Caddy detects the new service and domain from cluster state
- Initiates ACME challenge with Let’s Encrypt
- Obtains TLS certificate (usually takes a few seconds)
- Configures HTTPS listener with the certificate
- Automatically redirects HTTP to HTTPS
For the ACME challenge to succeed, your domain must resolve to your machine’s public IP via DNS A records.
Certificate Renewal
Caddy automatically renews certificates:- Certificates are checked daily
- Renewal begins 30 days before expiration
- Renewal is fully automatic, no manual intervention needed
- Zero downtime during renewal
Certificate Storage
Certificates are stored in:- Local storage on each machine running Caddy
- Caddy container volume at
/data/caddy
Managed DNS with uncld.dev
Uncloud provides free managed DNS for quick deployments without configuring your own DNS.Cluster Domain
When you initialize a cluster, Uncloud reserves a unique subdomain:Automatic DNS Updates
Uncloud automatically manages DNS records:- When machines running Caddy come online, their IPs are added to DNS
- When machines go offline, their IPs are removed
- DNS updates propagate within seconds
- A records point to all internet-reachable machines running Caddy
Managed DNS uses round-robin DNS for simple load distribution across multiple machines.
Service Subdomain
You can publish services without specifying the full domain:Custom Domains
To use your own domain, add DNS records pointing to your machines.DNS Configuration
- Get your machine IPs:
- Create DNS A records in your DNS provider:
- Deploy your service:
- Wait for DNS propagation (typically 1-5 minutes)
-
Access your service at
https://myapp.example.com
Caddy will automatically obtain a Let’s Encrypt certificate for your custom domain.
Wildcard Domains
You can use wildcard DNS with custom domains:- Create a wildcard A record:
- Publish services with subdomains:
Load Balancing
Caddy automatically load balances across service replicas.How Load Balancing Works
- Three containers start across available machines
- Caddy discovers all container IPs via DNS (
api.internal) - Incoming requests are distributed across all three containers
- Health checks automatically remove unhealthy containers from rotation
Load Balancing Strategy
Caddy uses round-robin load balancing by default:- Each request goes to the next container in rotation
- Simple and fair distribution
- No sticky sessions or IP-based affinity
For more advanced load balancing strategies, you can use Caddy’s custom configuration.
Health Checks
Caddy integrates with Docker health checks to avoid sending traffic to unhealthy containers.Configure Health Checks
- Monitor container health status
- Automatically remove unhealthy containers from load balancing
- Restore containers when they become healthy again
Health checks are configured at the Docker level, not in Caddy. Caddy reads the health status from cluster state.
Multiple Machines and High Availability
Since Caddy runs in global mode, every machine can handle ingress traffic.DNS-Based Failover
With multiple A records:- Try the first IP
- Automatically failover to second IP if first is unreachable
- This provides basic high availability
Geographic Distribution
Spread machines across regions:- Lower latency for users worldwide
- Better fault tolerance
- Continued operation if a region goes down
Uncloud’s managed DNS automatically updates records to only include reachable machines.
Advanced Caddy Configuration
For advanced use cases, you can provide custom Caddy configuration.Custom Caddyfile
Publishing Non-HTTP Services
Caddy is designed for HTTP/HTTPS traffic. For TCP/UDP services, use host mode ports:Viewing Endpoints
List all exposed service endpoints:- Service name
- Exposed URLs (both custom domains and cluster domains)
- Backend container ports
Troubleshooting
Certificate Errors
If HTTPS isn’t working:- Check DNS resolution:
- Check Caddy logs:
- Verify port 443 is accessible:
Connection Refused
If you get “connection refused”:- Verify service is running:
uc ls - Check container is healthy:
uc ps service-name - Test internal connectivity:
curl http://service.internal:portfrom another container - Check Caddy configuration:
uc logs caddy
SSL Certificate Rate Limits
Let’s Encrypt has rate limits:- 50 certificates per domain per week
- 5 duplicate certificates per week
- Wait for the rate limit window to reset
- Use Let’s Encrypt staging environment for testing
- Avoid repeatedly deleting and recreating services with the same domain
Further Reading
Services
Learn about service deployment and scaling
Networking
Understand how traffic routes to containers
DNS Management
Step-by-step guide to using your own domains
Caddy Documentation
Official Caddy documentation for advanced features
