How to use Cloudflare to protect a Discourse site

Hey, admins, I keep wondering how to using cloudflare or proxy to protecting a discourse site?

Hi @Lee_Kris, welcome to the Discourse Meta community!

I am assuming that this is for a self-hosted site. If your site is hosted by Discourse, they have you convered - there shouldn’t be any need to use Cloudflare or a proxy to protect your site.

If you are self-hosting the site, this is probably a question where it would be worth searching for previous questions about this. Cloudflare in particular can cause some issues with Discourse and requires some extra steps to be taken. Here’s a good post about that: Using the CloudFlare template - #2 by Stephen.

Note that that post mentions the need to add cloudflare.template.yml to your Discourse app.yml file. There are some additional details about that here: Full site CDN acceleration for Discourse.

I’d recommend searching on Search results for 'cloudflare' - Discourse Meta to find more discussions about this issue. Feel free to reply to any of those topics, or get back to us here with any questions that you have.

3 Likes

Hi Simon:

Yes, I am a self-hosted site, I have noticed can add to app.yml and then rebuild

  • “templates/cloudflare.template.yml”

More questions do I need to enable the below templates.yml to app.yml too or keep it disalbed?

  • “templates/web.ssl.template.yml”
  • “templates/web.letsencrypt.ssl.template.yml”

Also if I am using a proxy like Nginx with CF protected, can I change the default expose ports like below, then appending ssl get from CF by manually writing to nginx config file?
expose:
- “81:80”

- “443:443”

I just added that template and set my cloudflare SSL to full and enable the cloud and it worked

Are those templates enabled too?

  • “templates/web.ssl.template.yml”
  • “templates/web.letsencrypt.ssl.template.yml”