
DNS-only setup
This is the simplest and most reliable way to use Cloudflare with Fly.io. To configure a DNS-only setup:- Point your domain to your Fly.io app using an
AAAArecord for the IPv6 address and anArecord for the IPv4 address. - Alternatively, use a
CNAMErecord pointing to your appās unique target, shown in your certificate setup instructions. - Disable the Cloudflare proxy (select āgrey cloudā) for these records.
- SSL certificates will be handled by Fly.io automatically using Letās Encrypt.
CDN proxy setup (āorange cloudā)
Enabling Cloudflareās proxy gives you caching and DDoS protection, but it also changes how SSL certificates work. Cloudflare terminates TLS traffic, which means Fly.io canāt use its default TLS-ALPN-01 certificate issuance process. The key to a smooth setup is a_fly-ownership TXT record that proves domain ownership to Fly.io and allows certificate validation to work through Cloudflareās proxy.
Important: Wildcard certificates (e.g.
*.example.com) cannot be issued automatically through Cloudflareās proxy, because Letās Encrypt requires a DNS-01 challenge for wildcards and Cloudflareās Universal SSL can interfere with it. To use a wildcard certificate behind Cloudflareās proxy, import a Cloudflare Origin Certificate instead.Recommended setup
- Add your domain to your Fly app:
- Add a
_fly-ownershipTXT record in Cloudflare DNS. Runfly certs setupto see the required record:
-
Configure your DNS records in Cloudflare:
- Add an
Arecord pointing to your Fly appās IPv4 address. - Add an
AAAArecord pointing to your Fly appās IPv6 address. - Alternatively, use a
CNAMErecord pointing to your appās.fly.devtarget. - Enable the Cloudflare proxy (orange cloud) for these records.
- Add an
- Set SSL mode in Cloudflare to Full (strict).
- Enable Always Use HTTPS in Cloudflare (recommended).
fly certs check example.com to monitor validation progress.
Some Cloudflare configurations will block HTTP-01 challenges altogether. If certificate issuance is not progressing, import a Cloudflare Origin Certificate instead.
Using a Cloudflare Origin Certificate
If automatic certificate issuance doesnāt work for your setup, or if you need a wildcard certificate (like*.example.com), you can import a Cloudflare Origin Certificate instead.
-
Generate a Cloudflare Origin Certificate in the Cloudflare dashboard:
- Go to SSL/TLS > Origin Server > Create Certificate.
- Choose the hostnames to cover (for example,
example.comand*.example.com). - Choose a validity period (Cloudflare offers up to 15 years).
- Keep the page open ā Cloudflare only shows the private key once.
- Import the certificate to Fly.io in your app dashboard under Certificates. You can paste the certificate and private key directly from Cloudflare. Alternatively, save them as files and use the CLI:
-
Add the
_fly-ownershipTXT record shown in the certificate setup details, if you havenāt already set one up. - Configure your DNS records and Cloudflare SSL mode as described in the recommended setup above.
Custom and ACME certificates can coexist for the same hostname. The custom certificate is served as primary, and any ACME certificate acts as an automatic fallback.
Common issues to watch for
General issues
- Always use āFull (strict)ā in Cloudflare when connecting to Fly.io. Using āFlexibleā mode may cause redirect loops.
- Only one application should manage certificates for a subdomain or apex domain. Using more than one can cause conflicts.
ACME-specific issues
These issues apply when using Letās Encrypt (ACME) certificates behind Cloudflareās proxy. They do not apply if you are using a Cloudflare Origin Certificate.- Check that your domain allows Letās Encrypt with a CAA record like:
- Letās Encrypt has rate limits. Check the certificate status tab in the Fly.io dashboard if issuance fails.
- DNS-01 certificates will conflict with Cloudflare Universal SSL. This happens when Cloudflareās Universal SSL automatically inserts hidden ACME challenge TXT records that donāt appear in your DNS dashboard. These ghost records interfere with Letās Encryptās validation process. The best choice in this situation is to import a Cloudflare Origin Certificate instead.
Custom certificate issues
- Unlike Letās Encrypt certificates, which renew automatically, custom certificates must be manually renewed and re-imported before they expire. Cloudflare Origin Certificates can be issued with long validity periods (up to 15 years), but you should still track expiry.
Tools for debugging
These tools can help when diagnosing certificate or DNS issues:fly certs check <hostname>: Check ownership TXT status, custom certificate status, and ACME certificate status all in one place. This is the best starting point for debugging.- crt.sh: Check issued certificates.
- DNSChecker: Confirm DNS propagation.
- Letās Debug: Analyze Letās Encrypt certificate validation issues.
- dig: Inspect DNS records from the command line.