How Exactly should I add cloudflare CDN to discourse?

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?

Did you check these?

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.

5 Likes

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?

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) Part 11 :: Set up CloudFlare with your Droplet! - Digital Ocean Tutorials - YouTube

Step 2: Make Swap Files

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

Step 4: start to install Let’s Encrypt

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

Uncomment and change these line

Add Email Let’s Encrypt

Then Rebuild Discourse App

/var/discourse/launcher rebuild app

After Rebuild App,

access to CloudFlare to enable SSL Full strict

Yes!, It’s Done!

4 Likes

@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 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)

Hi,

I think you Add Your Domain to Cloudflare first

you can follow this

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 :smiley:

I hope it useful,

about Txt, MX, Cname, I use for Email

1 Like