hosting:caddy:multiple_services
Table of Contents
Multiple Services
Run multiple services behind Caddy with proper routing.
Caddy can route traffic to multiple services based on domain or path.
Overview
Caddy can route traffic to multiple backend services based on domain name or path. This allows you to host multiple applications on a single server.
Complete docker-compose.yml
```yaml services:
caddy:
image: caddy:2-alpine
container_name: caddy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
networks:
- app-network
whoami:
image: traefik/whoami:latest
container_name: whoami
restart: unless-stopped
networks:
- app-network
nginx:
image: nginx:alpine
container_name: nginx
restart: unless-stopped
networks:
- app-network
networks:
app-network:
volumes:
caddy_data: caddy_config:
```
Caddyfile for Multiple Services
``` your-domain.com {
reverse_proxy whoami:80
}
api.your-domain.com {
reverse_proxy nginx:80
} ```
Service Discovery
All services on the same network can reach each other by service name. Caddy can reach `whoami:80` and `nginx:80` because they share the `app-network`.
Adding New Services
To add a new service:
1. Add service to docker-compose.yml 2. Add entry to Caddyfile 3. Restart services
References
See Also
hosting/caddy/multiple_services.txt · Last modified: by 127.0.0.1
