Configure Cloudflare

Templ has partnered with Cloudflare, allowing you to access Cloudflare's features directly through Templ.

Why use Cloudflare with Templ

Cloudflare's free global CDN serves your content from data centers around the world, which strengthens your site's security and cuts your bandwidth costs by offloading traffic from the origin server. On top of that, Cloudflare protects your site against threats like DDoS attacks.

For sites that want to squeeze out even more performance, Cloudflare offers Automatic Platform Optimization (APO) as a paid add-on, which further reduces Time to First Byte (TTFB) and First Contentful Paint (FCP). All setup is handled by Templ.

While Cloudflare's features eventually will be available in the Templ Panel, you can start enjoying the benefits of Cloudflare through Templ immediately.

Once your site is behind Cloudflare, you can also add WAF rules to block spam bots at the edge.

Get started

To enable this, we need to change your name servers and access your current DNS zone. If your domain and DNS are not already managed by Templ, we would appreciate it if you could transfer them to Templ first for a seamless experience.

Once that's done, simply contact our support team to get started. If you'd like direct access to the Cloudflare dashboard for your site, just let us know and we'll set it up for you.

Pricing

It's free of charge to use Cloudflare with Templ; however, please note that some Cloudflare products, such as Automatic Platform Optimization (APO) or other specific features, may incur additional costs.

Using your own Cloudflare account

You're welcome to set up Cloudflare yourself in your own account if you prefer. That said, we strongly recommend letting us handle the Cloudflare setup for you. This way we can offer managed DNS and more extensive support, just like you're used to.

If you'd like our help, contact our support team.

Clearing the Cloudflare cache

There are two ways to clear the Cloudflare cache:

  • Via the Cloudflare dashboard: Under Caching → Configuration, clear the entire cache (Purge Everything) or perform a custom purge.
    Cloudflare dashboard cache purge options
  • Using the WordPress plugin: Install the Cloudflare WordPress plugin to manage cache and settings directly from WP Admin.

Troubleshooting

Error "ERR_TOO_MANY_REDIRECTS"

  • Cause: This occurs when SSL is set to 'Flexible' mode in Cloudflare while SSL is already configured on the server.
  • Solution: In the Cloudflare dashboard, go to SSL/TLS → Overview and change the encryption mode to 'Full'.

Cloudflare SSL/TLS encryption mode set to Full

Error 520

Cloudflare returns a 520 error when it receives an unexpected or empty response from the origin server. There are two common causes:

  • HTTP/2 to Origin. These errors can often be avoided by disabling HTTP/2 to Origin in Cloudflare, under Speed → Settings → Protocol Optimization.
    Cloudflare HTTP/2 to Origin setting under Protocol Optimization
  • The domain isn't linked to any website. Attach it first - see Additional domains.

SSL certificate is missing and never gets generated

  • Cause: While a domain is proxied through Cloudflare, it resolves to Cloudflare's IPs instead of Templ's. Automatic SSL generation is not retried for proxied domains, so a missing certificate will not fix itself while the proxy is on.
  • Solution: Temporarily switch the @ and www records to DNS only (grey cloud) in Cloudflare, generate the certificate manually, then re-enable the proxy. See SSL certificates for step-by-step instructions.