CDN: Fastly or Cloudflare for Discourse sites


(James) #1

I saw that Meta runs and recommends Fastly but I’ve also seen on Meta that Cloudflare is also recommended.

What is truly the best option for a discourse-run site? Pros and Cons? Thanks.

Price doesn’t really matter for me


(Dan) #2

Cloudflare, free and it works fine.


(Geran Smith) #3

Cloudflare is probably less of a proper CDN than Fastly, so if you need a proper CDN I think Fastly would be a better choice.


(James) #4

I signed up on Cloudflare and I updated my DNS records to match it and it says the site is active. Now is there anything to apply or is that simply all?


(Makary Gołosz) #5

Have you seen this guide?


(James) #6

Yes, but for Cloudflare I dont see any of those 3 options highlighted.

What you’re looking for is three main settings:

  1. The origin address , which is the URL where your forum is currently located discourse.example.com . This is where the CDN will draw all its original content from on first request.

  2. The CNAME , which is the “friendly” name for your CDN that you’ll set up in your DNS, e.g. discourse-cdn.example.com

  3. The CDN URL , which is the “unfriendly” name for where the cached CDN assets will be coming from via the CDN’s worldwide network of distributed servers. It will look like 637763234.cdn-provider.com


(Makary Gołosz) #7

Then perhaps this one, specific to Cloudflare?


(James) #8

I placed cloudflare.template.yml at the end of the templates section in app.yml and it’s giving an error whilst rebuilding the app, saying no such directory was found.


(Makary Gołosz) #9

Did the line look like this?

  - templates/cloudflare.template.yml

(James) #11

Ah that works. :sweat_smile: Is that all? I’m sorry I’m trying hard to understand this process but I’m not very skilled in this field.


(Stephen) #12

That’s what you’ll need for Discourse to once again see the originating IP of your users. Without the template all of your users appear to come from CloudFlare IP addresses. Cloudflare inserts the user IP in the header and the template makes that information available.

What it doesn’t do is use the CloudFlare API to flush objects from the cache, but as Discourse manages the names of files and images there’s not much risk a reupload will continue to serve the original object.


(James) #13

That makes sense, like a filter.

Then what additional procedures are required to get Cloudflare to fully work with discourse?


(Stephen) #14

As long as you don’t change the default caching rules nothing.

If you ignore querystrings, or try to replace uploads directly via file filesystem, then you will need to log into Cloudflare directly to expire the cache.