# Traefik ACME Challenge Switching Guide This guide explains how to switch SSL certificate issuance in this stack between DNS-01 and HTTP-01 challenge types. ## When to use each challenge - Use DNS-01 if Let’s Encrypt cannot reach your server from the internet. - Use HTTP-01 if port 80 on your public domains is reachable by Let’s Encrypt. ## Prerequisites - The stack is configured with Traefik and ACME enabled. - You are editing the environment file used by Docker Compose, usually .env. ## Switch to DNS-01 (Cloudflare) 1. Edit your .env and set: ```env TRAEFIK_SERVICES_TLS_CONFIG=tls.certresolver=letsencrypt TRAEFIK_ACME_MAIL=devops@example.com TRAEFIK_ACME_CHALLENGE=dns TRAEFIK_ACME_DNS_PROVIDER=cloudflare CF_DNS_API_TOKEN=your-cloudflare-api-token # Optional for split-DNS or propagation issues: # TRAEFIK_ACME_DNS_RESOLVERS=1.1.1.1:53,8.8.8.8:53 ``` 2. Restart Traefik: ```bash docker compose up -d traefik ``` 3. Verify challenge mode in logs: ```bash docker compose logs -f traefik ``` Look for log output indicating ACME DNS challenge usage. ## Switch to HTTP-01 1. Edit your .env and set: ```env TRAEFIK_SERVICES_TLS_CONFIG=tls.certresolver=letsencrypt TRAEFIK_ACME_MAIL=devops@example.com TRAEFIK_ACME_CHALLENGE=http TRAEFIK_ACME_DNS_PROVIDER=cloudflare CF_DNS_API_TOKEN= ``` 2. Ensure public inbound access from Let’s Encrypt to port 80 on each domain. 3. Restart Traefik: ```bash docker compose up -d traefik ``` 4. Check Traefik logs for HTTP challenge activity: ```bash docker compose logs -f traefik ``` ## Common issues - DNS-01 fails with Cloudflare: - Verify CF_DNS_API_TOKEN is set. - Ensure the token has DNS edit permissions on the correct zone. - HTTP-01 fails: - Ensure port 80 is open and routed to Traefik. - Check firewall, NAT, and upstream proxy settings. ## Quick rollback If issuance fails, switch back to the previous working challenge type in .env and restart Traefik: ```bash docker compose up -d traefik ``` ## Alternative method: use your own certificate files (no ACME) Use this method if you already have a certificate and private key and do not want Traefik to request certificates from Let's Encrypt. 1. Place your certificate and key files in the mounted cert directory: ```bash cp your-cert-fullchain.pem certs/custom.crt cp your-private-key.pem certs/custom.key chmod 644 certs/custom.crt chmod 600 certs/custom.key ``` Important: `certs/custom.crt` should contain the leaf certificate plus intermediate chain in PEM format. 2. Configure Traefik dynamic TLS certs in `config/traefik/dynamic/certs.yml`: ```yaml tls: certificates: - certFile: /certs/custom.crt keyFile: /certs/custom.key stores: - default ``` 3. Switch services to static TLS mode in `.env`: ```env TRAEFIK_SERVICES_TLS_CONFIG=tls=true ``` 4. Restart Traefik: ```bash docker compose up -d traefik ``` 5. Verify the served certificate: ```bash echo | openssl s_client -connect your-server-ip:443 -servername your-domain.tld 2>/dev/null | openssl x509 -noout -subject -issuer -dates ``` ### Wildcard option for multiple subdomains For domains like `cloud.example.com`, `git.example.com`, and `odoo.example.com`, you can use one wildcard certificate for `*.example.com`. Example dynamic config: ```yaml tls: certificates: - certFile: /certs/wildcard.example.com.crt keyFile: /certs/wildcard.example.com.key stores: - default ``` Notes: - Wildcards cover one label only (`*.example.com`), not the apex (`example.com`) unless it is included separately. - Keep `TRAEFIK_SERVICES_TLS_CONFIG=tls=true` while using custom certificates.