Setting Up Coolify with a Custom Domain and SSL Certificates Using Traefik and Cloudflare - A Comprehensive Guide
Setting up a custom domain and SSL certificates for Coolify with Traefik and Cloudflare.
๐ Setting Up Coolify with a Custom Domain and SSL Certificates Using Traefik and Cloudflare: A Comprehensive Guide
Coolify is a powerful self-hosted PaaS that simplifies application deployment, but setting up a custom domain with SSL certificates using Traefik can be tricky. After facing numerous challenges while configuring Coolify with Traefik as a reverse proxy and Cloudflare as the DNS provider, I've written this guide to save you time and frustration. Here, I'll walk you through the issues I encountered, the solutions I implemented, and the final working configuration. ๐
The Challenge: Custom Domain and SSL Setup with Traefik
Coolify uses Traefik as its proxy to handle SSL certificates via Let's Encrypt. My goal was to:
<your-domain>.tech) with Cloudflare as the DNS provider.*.your-domain.tech).Key Problems I Faced:
DNS Misconfiguration:
acme: error: 400 :: urn:ietf:params:acme:error:dns :: no valid A records found for <your-domain>.techCloudflare API Token Permissions:
acme: error presenting token: Cloudflare: failed to find zone <your-domain>.tech: Zone could not be foundConflicting HTTP and DNS Challenges:
Lack of Clear Documentation:
The Solution: A Step-by-Step Guide
Here's the final process I followed to configure the custom domain and SSL certificates successfully. ๐ก
1. Set Up DNS Records in Cloudflare
Make sure your domain is managed in Cloudflare and that the DNS records are properly configured:
<your-domain>.tech โ <Server IP>*.your-domain.tech โ <Server IP>2. Generate a Cloudflare API Token
Create an API token in Cloudflare with the following permissions:
Steps:
<your-domain>.tech) for added security. ๐3. Configure Traefik
Here's the generic Traefik configuration that you can adapt for your own use:
version: '3.8'
networks:
coolify:
external: true
services:
traefik:
container_name: coolify-proxy
image: 'traefik:v3.1'
restart: unless-stopped
environment:
- CF_DNS_API_TOKEN=<Your Cloudflare API Token> # Replace with your API token
extra_hosts:
- 'host.docker.internal:host-gateway'
networks:
- coolify
ports:
- '80:80'
- '443:443'
- '443:443/udp'
- '8080:8080'
healthcheck:
test: 'wget -qO- http://localhost:80/ping || exit 1'
interval: 4s
timeout: 2s
retries: 5
volumes:
- '/var/run/docker.sock:/var/run/docker.sock:ro'
- '/data/coolify/proxy:/traefik'
command:
- '--ping=true'
- '--ping.entrypoint=http'
- '--api.dashboard=true'
- '--api.insecure=false'
- '--entrypoints.http.address=:80'
- '--entrypoints.https.address=:443'
- '--entrypoints.http.http.encodequerysemicolons=true'
- '--entryPoints.http.http2.maxConcurrentStreams=50'
- '--entrypoints.https.http.encodequerysemicolons=true'
- '--entryPoints.https.http2.maxConcurrentStreams=50'
- '--entrypoints.https.http3'
- '--providers.docker.exposedbydefault=false'
- '--providers.file.directory=/traefik/dynamic/'
- '--providers.file.watch=true'
- '--certificatesresolvers.letsencrypt.acme.dnschallenge.provider=cloudflare' # Use Cloudflare for DNS challenge
- '--certificatesresolvers.letsencrypt.acme.dnschallenge.delaybeforecheck=0'
- '--certificatesresolvers.letsencrypt.acme.storage=/traefik/acme.json'
- '--providers.docker=true'
labels:
- traefik.enable=true
- traefik.http.routers.traefik.entrypoints=http
- traefik.http.routers.traefik.service=api@internal
- traefik.http.routers.traefik.tls.certresolver=letsencrypt
- traefik.http.routers.traefik.tls.domains[0].main=<your-domain>.tech # Replace with your main domain
- traefik.http.routers.traefik.tls.domains[0].sans=*.your-domain.tech # Replace with your wildcard domain
- traefik.http.services.traefik.loadbalancer.server.port=8080
- traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https
- traefik.http.middlewares.gzip.compress=true
- coolify.managed=true
- coolify.proxy=trueKey Tips:
httpchallenge). ๐ซdelaybeforecheck=0 to avoid unnecessary delays during DNS validation.4. Restart and Monitor
Troubleshooting Common Issues
DNS Zone Not Found:
No Valid A Records:
Invalid API Token:
CF_DNS_API_TOKEN in your configuration.Resources
Conclusion
Setting up a custom domain and SSL certificates for Coolify with Traefik and Cloudflare requires careful attention to DNS configuration and API token permissions. By following this guide, you can avoid common pitfalls and ensure a smooth setup for your applications. ๐