# How Exactly should I add cloudflare CDN to discourse?

**URL:** https://meta.discourse.org/t/how-exactly-should-i-add-cloudflare-cdn-to-discourse/55706
**Category:** Self-hosting
**Tags:** cdn
**Created:** [13 Gennaio 2017, 3:32pm UTC](https://meta.discourse.org/t/how-exactly-should-i-add-cloudflare-cdn-to-discourse/55706 "2017-01-13T15:32:51Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![azaleas](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@azaleas](https://meta.discourse.org/u/azaleas)
#### Post date: [13 Gennaio 2017, 3:32pm UTC](https://meta.discourse.org/t/how-exactly-should-i-add-cloudflare-cdn-to-discourse/55706/1 "2017-01-13T15:32:51Z")

</div>

I’ve been trying to add cloudflare cdn to my discourse forum. Couldnt find any direct tutorials or faqs. I added my domain to cloudflare, configured the cdn option, got my cloudflare name servers and then changed my digital ocean name servers to the ones that I got. After a while my forum was down.

I added the template to my yml file for cloudflare ssl, tried to rebuild everything. No luck. Site was down.

So I went to my previous setup with Lets Encrypt free SSL, removed all the code for cloudflare, changed my name servers back to digital ocean and now everything is working.

How do you guys installed this cdn? I’m building a small forum/first forum, so I don’t want to pay for CDN. So if there’re any other free alternatives for this that would be ok too.

Any help would be appreciated.

ps: I was leaning towards the idea that site was down due to the name servers changing from Digital Ocean to Cloudflare. Any ideas?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [13 Gennaio 2017, 3:58pm UTC](https://meta.discourse.org/t/how-exactly-should-i-add-cloudflare-cdn-to-discourse/55706/2 "2017-01-13T15:58:23Z")

</div>

> [@azaleas](#):
>
> I’ve been trying to add cloudflare cdn to my discourse forum. Couldnt find any direct tutorials or faqs.

Did you check these?

> [@Install Discourse on Amazon Web Services (AWS)](https://meta.discourse.org/t/install-discourse-on-amazon-ws-with-cloudflare/37323):
>
> warning This installation method is not officially endorsed. Use at your own risk. The Discourse team only recommend installation using the [official install guide](https://github.com/discourse/discourse/blob/master/docs/INSTALL-cloud.md) This guide originally included information about cloudflare, but @pfaffman thinks that conflating AWS and cloudflare is a bad idea. If you’re an AWS user, AWS Cloudfront makes much more sense than Cloudflare. @pfaffman edited this a good bit on 2022.11.21; if something seems broken, blame me. If it works, thank the original auth…

> [@Force Discourse to use SSL/HTTPS through CloudFlare](https://meta.discourse.org/t/force-discourse-to-use-ssl-https-through-cloudflare/49212):
>
> How to use CloudFlare’s platform to force all traffic over HTTPS connection using page rules. This is an up to date and user-friendly (fool-proof) way that I use each time and it works perfectly. Sign up to CloudFlare [here](https://cloudflare.com) - they offer SSL/HTTPS on their Free plan, so that will be just fine for us. Add your site [here](https://www.cloudflare.com/a/add-site) - the system will scan for DNS records, make sure all are correct and add any records not picked automatically by the scan i.e. MX records. You will the have to add the CloudFl…

> [@azaleas](#):
>
> I’m building a small forum/first forum, so I don’t want to pay for CDN.

If it’s a small forum, why bother with CDN? It would seem that if you had a big enough forum to require a CDN, then you’d have the money to pay for one.

---

<div class="post-metadata">

### Author: ![azaleas](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@azaleas](https://meta.discourse.org/u/azaleas)
#### Post date: [13 Gennaio 2017, 4:23pm UTC](https://meta.discourse.org/t/how-exactly-should-i-add-cloudflare-cdn-to-discourse/55706/3 "2017-01-13T16:23:51Z")

</div>

Yeap, I checked those. But I couldnt get it work.

Yeap, the forum is small. But I would like to test the CDN configuration. To see how it all works together. I realize that it won’t be necessary now. But even after the forum hits certain traction free CDN will do the trick until some point. Wouldnt it?

---

<div class="post-metadata">

### Author: ![Nam\_Nguyen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nam_nguyen/32/68634_2.png) [@Nam\_Nguyen](https://meta.discourse.org/u/Nam_Nguyen)
#### Post date: [13 Gennaio 2017, 4:24pm UTC](https://meta.discourse.org/t/how-exactly-should-i-add-cloudflare-cdn-to-discourse/55706/4 "2017-01-13T16:24:39Z")

</div>

Hi,  
I do these steps:

## Step 1: add Droplet to Cloudflare

Here is tutorials (just in case you don’t know how to add Droplet to Cloudflare and Domain) [https://www.youtube.com/watch?v=iWaFAIRWsA4](https://www.youtube.com/watch?v=iWaFAIRWsA4)

## Step 2: Make Swap Files

> **[How To Add Swap Space on Ubuntu 16.04 | DigitalOcean](https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04)**
>
> One of the easiest way of increasing the responsiveness of your server and guarding against out of memory errors in your applications is to add some swap spa…

Then Configure Local time

```
dpkg-reconfigure tzdata

```

## Step 3: Install Discourse

```
sudo -s
mkdir /var/discourse
git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse

```

**_I customize Default Email and Edit `app.yml` (You can Skip this and install Discourse as normal)_**

Copy the samples/standalone.yml file into the containers folder as app.yml:

```
sudo cp samples/standalone.yml containers/app.yml

sudo nano containers/app.yml

```

Change these line

```
DISCOURSE_HOSTNAME: 'domain.com'
DISCOURSE_DEVELOPER_EMAILS: 'me@example.com'
DISCOURSE_SMTP_ADDRESS: smtp.mandrillapp.com # (mandatory)
DISCOURSE_SMTP_PORT: 587 # (optional)
DISCOURSE_SMTP_USER_NAME: login@example.com # (optional)
DISCOURSE_SMTP_PASSWORD: pas$word # (optional)

```

Uncoment and Edit custom default Email on this line

`- exec: rails r "SiteSetting.notification_email='example@domain.com'"`

–\>\>\>\> Save the `app.yml` file, and exit the text editor.

**Bootstrap Discourse:**

```
sudo ./launcher bootstrap app

```

After the bootstrap process completes, start Discourse:

```
sudo ./launcher start app

```

After Start Discourse,

Access to your website: `domain.com`

**Install Discouse Wizard**

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

## Step 4: start to install **Let’s Encrypt**

```
cd /var/discourse
sudo nano containers/app.yml

```

Uncomment and change these line

 ![](https://global.discourse-cdn.com/meta/original/3X/d/0/d0d4f029fc5b4c8c4a0180ff4ce5cec12cbe915c.png)

**Add Email Let’s Encrypt**

![](https://global.discourse-cdn.com/meta/original/3X/0/6/06a3fe0031cdbc6f791f9a3c62fac8dad8b75c82.png)

Then Rebuild Discourse App

```
/var/discourse/launcher rebuild app

```

After Rebuild App,

access to CloudFlare to enable SSL Full strict

[![](https://global.discourse-cdn.com/meta/optimized/3X/8/5/85794d6486bd774451560860da22129facc83b57_1_690x358.PNG) ](https://global.discourse-cdn.com/meta/optimized/3X/8/5/85794d6486bd774451560860da22129facc83b57_1_690x358.PNG)

Yes!, It’s Done!

---

<div class="post-metadata">

### Author: ![azaleas](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@azaleas](https://meta.discourse.org/u/azaleas)
#### Post date: [13 Gennaio 2017, 4:53pm UTC](https://meta.discourse.org/t/how-exactly-should-i-add-cloudflare-cdn-to-discourse/55706/5 "2017-01-13T16:53:30Z")

</div>

@Nam_Nguyen thanks for these steps. What exactly do you add to cloudlare? Just the root domain or all the other paths as well, like MX and TXT? Now, when I add my domain to cloudflare, it shows these as passing via CDN:

**type A =\> forum points to digitalOceanIP**  
**type A =\> [domain.com](http://domain.com) points to digitalOceanIP**  
**type A =\> www.forum points to digitalOceanIP**  
**type A =\> www points to digitalOceanIP**

_(I added redirects for root and www paths to my forum subdomain)_

MX and TXT aren’t passing via Cloudflare.

**is this similar to yours?**

What I did after this step is I copied the CloudFlare name servers that were generated for my domain and added them on my registrar.

And after couple of minutes my site was down.

I didnt follow the steps exactly. Rather I added cloudflare the last. Regular discourse installation + LetsEncrypt SSL + Cloudflare CDN (here I stuck, so I had to go back one step)

---

<div class="post-metadata">

### Author: ![Nam\_Nguyen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nam_nguyen/32/68634_2.png) [@Nam\_Nguyen](https://meta.discourse.org/u/Nam_Nguyen)
#### Post date: [13 Gennaio 2017, 5:04pm UTC](https://meta.discourse.org/t/how-exactly-should-i-add-cloudflare-cdn-to-discourse/55706/6 "2017-01-13T17:04:54Z")

</div>

Hi,

I think you Add Your Domain to Cloudflare first

you can follow this

[https://support.cloudflare.com/hc/en-us/articles/201720164-Step-2-Create-a-CloudFlare-account-and-add-a-website](https://support.cloudflare.com/hc/en-us/articles/201720164-Step-2-Create-a-CloudFlare-account-and-add-a-website)

Then Connect Cloudflare to Your Cloud Server

Add

Type A ;Name @ ; Value your Server IP4

Type A ; Name www ; Value your server IP4

and similar to IP6 (optional)

If you use subdomain, watch again this 😃

> [@Nam\_Nguyen](#):
>
> [https://www.youtube.com/watch?v=iWaFAIRWsA4](https://www.youtube.com/watch?v=iWaFAIRWsA4)

I hope it useful,

about Txt, MX, Cname, I use for Email

---

<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: [20 Aprile 2019, 6:51pm UTC](https://meta.discourse.org/t/how-exactly-should-i-add-cloudflare-cdn-to-discourse/55706/7 "2019-04-20T18:51:37Z")

</div>



---

<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: [24 Aprile 2019, 5:54pm UTC](https://meta.discourse.org/t/how-exactly-should-i-add-cloudflare-cdn-to-discourse/55706/8 "2019-04-24T17:54:42Z")

</div>


