# How do you setup Cloudflare?

**URL:** https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258
**Category:** Support
**Created:** [August 18, 2015, 5:28pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258 "2015-08-18T17:28:32Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![emanger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanger/32/44983_2.png) [@emanger](https://meta.discourse.org/u/emanger)
#### Post date: [August 18, 2015, 5:28pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/1 "2015-08-18T17:28:32Z")

</div>

Hi,

I was told a while back that I had to add a line to enable CloudFlare compatibility? Can someone please explain to me the exact steps to do so?

I would like to enable and use CloudFlare for my website.

All help is much appreciated!

---

<div class="post-metadata">

### Author: ![emanger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanger/32/44983_2.png) [@emanger](https://meta.discourse.org/u/emanger)
#### Post date: [August 18, 2015, 5:54pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/3 "2015-08-18T17:54:28Z")

</div>

Hey,

I can’t access that account anymore which is why I am making a fresh topic.

I am unaware on how to edit the config to include those lines? All help is appreciated.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [August 18, 2015, 5:55pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/4 "2015-08-18T17:55:32Z")

</div>

> [@emanger](#):
>
> I can’t access that account anymore

Mind explaining why? Have you tried to reset the password?

---

<div class="post-metadata">

### Author: ![emanger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/emanger/32/44983_2.png) [@emanger](https://meta.discourse.org/u/emanger)
#### Post date: [August 18, 2015, 5:58pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/5 "2015-08-18T17:58:46Z")

</div>

I used Putty to add the line at the end of templates - but when I attempted to rebuild the app, it said that the CloudFlare YML file was missing.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [August 18, 2015, 8:46pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/6 "2015-08-18T20:46:44Z")

</div>

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

Here’s how to edit in a nutshell:

```
cd /var/discourse
nano containers/app.yml
# Make sure to use spaces, not the tab key.
# Ctrl-O to "write [O]ut"
# Ctrl-X to "e[X]it"

./launcher rebuild app

```

credit to @riking

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [August 25, 2015, 7:28am UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/7 "2015-08-25T07:28:10Z")

</div>

Wait a moment, this works and has worked for a very long time

> [@Full site CDN acceleration for Discourse](https://meta.discourse.org/t/full-site-cdn-acceleration-for-discourse/21467):
>
> [Fastly](http://www.fastly.com/) , [CloudFlare](https://www.cloudflare.com) and a few other CDNs offer a mode where they accelerate dynamic content. In a nutshell you point your domain IP address at the CDN and the CDN will intelligently decide how to deal with the request. Static content can be easily served from cache Dynamic content can be routed to the site. This provides some advantages over only shipping static assets which is covered in [the CDN howto](https://meta.discourse.org/t/enable-a-cdn-for-your-discourse/14857). You can elect for “[shielding](http://www.fastly.com/products/origin-shield/)” that protects your site from traffic spikes. Dynamic cont…

You must follow the guide, in particular ` long polling base url` MUST be set correctly to the origin otherwise the message bus will not work right. You must also mixin the cloudflare template so it does not look like everyone is coming from the same IP which is a disaster.

I think it’s fine to setup this way if you wish, but in general I prefer just to use cloudflare as a CDN endpoint and point the site at Discourse to avoid moving parts and a more complex setup for little gain.

---

<div class="post-metadata">

### Author: ![bekircem](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bekircem/32/44582_2.png) [@bekircem](https://meta.discourse.org/u/bekircem)
#### Post date: [September 13, 2017, 9:53am UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/8 "2017-09-13T09:53:18Z")

</div>

Solved most of problem. But still have problem with some new users has Digital Ocean’s VPS ip’s.

 ![problem](https://global.discourse-cdn.com/meta/original/3X/a/b/ab94030e3cdbe78609b70fa87ef5e403a42a5e6c.png)

Another example:

 ![pb2](https://global.discourse-cdn.com/meta/original/3X/9/8/98c1f3a1ad2df5f0d7501a1ccbc1183ba9805641.png)

My Discourse on the Frankfurt, Digital Ocean.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [September 16, 2017, 5:57am UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/9 "2017-09-16T05:57:40Z")

</div>

> [@bekircem](#):
>
> [google-proxy-66-249-93-218.google.com](http://google-proxy-66-249-93-218.google.com)

That’s the “Data Saver” proxy available on Android Chrome. It would be possible to add its IP range as a trusted X-Forwarded-For source. [matomo/core/Tracker/VisitExcluded.php at 5.x-dev · matomo-org/matomo · GitHub](https://github.com/piwik/piwik/blob/master/core/Tracker/VisitExcluded.php#L232-L241)

---

<div class="post-metadata">

### Author: ![Brock\_Busby](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brock_busby/32/118746_2.png) [@Brock\_Busby](https://meta.discourse.org/u/Brock_Busby)
#### Post date: [September 22, 2017, 1:14pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/10 "2017-09-22T13:14:10Z")

</div>

> [@sam](#):
>
> in particular long polling base url MUST be set correctly to the origin otherwise the message bus will not work right.

We are using Cloudflare and I’m a bit confused on what should be our `long polling base url`.  
Is it [site.com](http://site.com) or [discourse.site.com](http://discourse.site.com)? By default it already has / as the value.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [September 22, 2017, 3:45pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/11 "2017-09-22T15:45:11Z")

</div>

I’m fairly certain you have to include the scheme if you need it to point to a different domain.

---

<div class="post-metadata">

### Author: ![Brock\_Busby](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brock_busby/32/118746_2.png) [@Brock\_Busby](https://meta.discourse.org/u/Brock_Busby)
#### Post date: [September 22, 2017, 5:43pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/12 "2017-09-22T17:43:20Z")

</div>

I’m just trying to understand exactly what long polling base url is for Discourses purposes and if we need to declare it from the default “/” that is there. After reading @sam’s instructions, I’m still unclear what, if any, URL I should input for that config.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [September 22, 2017, 5:46pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/13 "2017-09-22T17:46:07Z")

</div>

In sam’s instructions:

> [@Full site CDN acceleration for Discourse](https://meta.discourse.org/t/full-site-cdn-acceleration-for-discourse/21467/1):
>
> For example, if your site is on “[http://forum.example.com](http://forum.example.com)” you should set up [http://forum-direct.example.com/](http://forum-direct.example.com/) to plug into the site setting. If you don’t your site will be broken.

The message bus long polling URL should be set to the non-CDN domain name that you set up

---

<div class="post-metadata">

### Author: ![Brock\_Busby](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brock_busby/32/118746_2.png) [@Brock\_Busby](https://meta.discourse.org/u/Brock_Busby)
#### Post date: [September 22, 2017, 7:39pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/14 "2017-09-22T19:39:56Z")

</div>

Maybe I’m dense and the language is stumping me…

Our site is [https://ftw.in](https://ftw.in)  
Our Discourse is [https://discussions.ftw.in](https://discussions.ftw.in)  
Both are behind Cloudflare.

So our long polling url is `https://discussions.ftw.in/`?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [September 22, 2017, 7:40pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/15 "2017-09-22T19:40:49Z")

</div>

No, your long polling URL would be

`https://discussions-origin.ftw.in/`

or, seeing as you have had DDOS problems: `https://discussions-proxy.ftw.in`

Where discussions-proxy is a non-Cloudflare server proxying the origin, but only for message-bus requests.

---

<div class="post-metadata">

### Author: ![Brock\_Busby](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brock_busby/32/118746_2.png) [@Brock\_Busby](https://meta.discourse.org/u/Brock_Busby)
#### Post date: [September 22, 2017, 9:22pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/16 "2017-09-22T21:22:44Z")

</div>

> [@riking](#):
>
> Where discussions-proxy is a non-Cloudflare server proxying the origin, but only for message-bus requests

Ok, this explanation definitely helps me understand more clearly, but this is also where I get lost. Is this documented where and how to create this server for message-bus requests?

Also - we want all servers to be behind Cloudflare for the protection and CDN it provides. We would not want to have it outside of Cloudflare.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [September 22, 2017, 10:16pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/17 "2017-09-22T22:16:53Z")

</div>

How: Just stand up a nginx with a single proxy\_pass rule at OVH (“the premier bargain basement cloud provider”) or something.

You CANNOT put long polling behind CloudFlare. They terminate long-running requests as, incidentally, a anti-DoS measure.

Because DDoS protection is a priority for you, set up this server at a DIFFERENT provider so attacks on it do not actually take down the main site; you just get degraded live update functionality.

---

<div class="post-metadata">

### Author: ![Brock\_Busby](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brock_busby/32/118746_2.png) [@Brock\_Busby](https://meta.discourse.org/u/Brock_Busby)
#### Post date: [September 23, 2017, 3:31pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/18 "2017-09-23T15:31:51Z")

</div>

Got it. Thanks for the help!

---

<div class="post-metadata">

### Author: ![SouperC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/souperc/32/62875_2.png) [@SouperC](https://meta.discourse.org/u/SouperC)
#### Post date: [October 8, 2017, 4:05am UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/19 "2017-10-08T04:05:05Z")

</div>

Not to be totally dense here. but I’m not sure if I am configured for cloudflare correctly or not. I setup our discourse install about a year ago, behind cloudllare and I don’t believe I setup anything for long polling… Notifications appear to be working OK.

Is there something else I should look for.?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [October 9, 2017, 12:03am UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/20 "2017-10-09T00:03:45Z")

</div>

In the past it has been flaky, somehow over the years cloudflare has figured out how to proxy long HTTP calls, I would not say it is an optimal config to pass the message bus through cloudflare, but it it is working for you and you are not noticing any issues, so be it.

---

<div class="post-metadata">

### Author: ![Raj\_Rathore](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/raj_rathore/32/155320_2.png) [@Raj\_Rathore](https://meta.discourse.org/u/Raj_Rathore)
#### Post date: [September 7, 2019, 7:36pm UTC](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258/21 "2019-09-07T19:36:33Z")

</div>

Should I proceed with following or let long polling through discourse subdomain which is proxied through Cloudflare?

I’m using Digital Ocean and I can set up a different subdomain, eg. [poll.mydomain.com](http://poll.mydomain.com) as the base and provide the same IP Address as the main website [www.mydomain.com](http://www.mydomain.com). The only difference is main site is proxied through Cloudflare and polling domain is not proxied i.e. orange cloud off. I’m hosting the discourse on www subdomain.

Will updates work if I continue to use polling to be proxied through CloudFlare ? If not, should use above approach, will that work without issue?

[Next page](https://meta.discourse.org/t/how-do-you-setup-cloudflare/32258.md?page=2)
