# Using the CloudFlare template

**URL:** https://meta.discourse.org/t/using-the-cloudflare-template/158334
**Category:** Self-hosting
**Created:** [July 21, 2020, 12:01am UTC](https://meta.discourse.org/t/using-the-cloudflare-template/158334 "2020-07-21T00:01:04Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![DigitalStartup](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/digitalstartup/32/118242_2.png) [@DigitalStartup](https://meta.discourse.org/u/DigitalStartup)
#### Post date: [July 21, 2020, 12:01am UTC](https://meta.discourse.org/t/using-the-cloudflare-template/158334/1 "2020-07-21T00:01:04Z")

</div>

A few hours ago, I setup Cloudflare as a CDN (grey cloud icon) for my Discourse site (`example.com`). I came across this afterwards:

> [@How do you setup Cloudflare?](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/6):
>
> Yes, just:
> 
> - add `cloudflare.template.yml` to the end of the templates section in `app.yml` .
> - do not enable Rocket Loader or any other features that will interfere with JavaScript

Therefore, I added (bottom line)

```plaintext
templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/web.template.yml"
  - "templates/web.ratelimited.template.yml"
## Uncomment these two lines if you wish to add Lets Encrypt (https)
  - "templates/web.ssl.template.yml"
  - "templates/web.letsencrypt.ssl.template.yml"
  - "templates/cloudflare.template.yml"

```

My question. Was this necessary when only using Cloudflare as a CDN for Discourse? Or did I misinterpret the instruction? I don’t want to be adding templates if it’s unnecessary.

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [July 21, 2020, 12:07am UTC](https://meta.discourse.org/t/using-the-cloudflare-template/158334/2 "2020-07-21T00:07:19Z")

</div>

In short, because CloudFlare isn’t a typical CDN.

The gray cloud means that CloudFlare is only serving DNS for that address.

If you turn on the orange cloud, it alters the IP address shown to the outside world and proxies all traffic across its network, which allows it to both ‘protect’ the server and cache assets such as images and javascript.

The template is necessary because once CloudFlare sits between your site and the outside world, your server will only see CloudFlare IPs as connecting to it. By using the template your site will once again see the client IPs which CloudFlare forward in the `CF-Connecting-IP` header.

Without this configured correctly you will see connection limit errors and encounter errors regarding registration IP addresses, as all user traffic appears to come from a handful of addresses.

If you decide to enable the CloudFlare CDN (orange cloud) you need to take one more step and establish a page rule for the address of your Discourse instance. The rule needs to ‘Disable Performance’ which will turn off the CloudFlare features which are well documented to interfere with Discourse.

Note that if you’re using CloudFlare to front your site, rather than an S3 bucket, that you’ve added additional network hops between your server and clients across the internet. Remember that Discourse isn’t a website, it’s a JavaScript application. Once Discourse has loaded in the browser it isn’t downloading pages when users click links. Adding those additional network hops will add a small but not entirely unnoticeable delay to every click.

Unless your site is under attack the smart way to use CloudFlare is to migrate your assets into S3 (object storage, rather than a CDN) and then use CloudFlare in front of that S3 storage. That way client communications remain snappy, asset download bandwidth is reduced and best of all you free up local storage on your Discourse server.

---

<div class="post-metadata">

### Author: ![Bill](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bill/32/159342_2.png) [@Bill](https://meta.discourse.org/u/Bill)
#### Post date: [July 21, 2020, 1:03am UTC](https://meta.discourse.org/t/using-the-cloudflare-template/158334/3 "2020-07-21T01:03:44Z")

</div>

I can’t believe I’ve been running my site for a year now without having Cloudflare correctly setup. I’m surprised I didn’t notice any errors. Thanks for the info!

---

<div class="post-metadata">

### Author: ![DigitalStartup](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/digitalstartup/32/118242_2.png) [@DigitalStartup](https://meta.discourse.org/u/DigitalStartup)
#### Post date: [July 21, 2020, 8:07am UTC](https://meta.discourse.org/t/using-the-cloudflare-template/158334/4 "2020-07-21T08:07:58Z")

</div>

Thanks, @Stephen. This was incredibly informative. My main take away is that Cloudflare probably wasn’t the right choice for me, given that traditional CDNs are less disruptive - Despite the lack of DDoS Protection.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [August 28, 2020, 10:40pm UTC](https://meta.discourse.org/t/using-the-cloudflare-template/158334/6 "2020-08-28T22:40:17Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
