CloudFlare and location for the users

AI-generated summary

A user, @kaziqta, is looking to use CloudFlare’s geo header to determine users’ locations. Although @justin advises against running all traffic through CloudFlare due to potential issues, @Stephen provides a template solution, cloudflare.template.yml, which can be added to the app.yml to pass the client IP forwarded by CloudFlare into Discourse.

@Stephen and @codinghorror discuss the limitations and potential drawbacks of using CloudFlare, including added latency and the possibility of IP leaks. However, @Stephen also notes that it can be a viable option for those who cannot afford a separate CDN.

@kaziqta successfully implements the template and also inquires about the impact of rebuilding on local translations. @pfaffman assures that translations made through the /admin/customize/text interface will be preserved during a rebuild.

Hi,
I see that when the users see logged in devices, Discourse shows the edge CloudFlare edge server location.
I have made so that the whole forum is behind CloudFlare, is there an option to use the CloudFlare geo header, after all the server will have it received.

Welcome @kaziqta! Unfortunately we don’t recommend running all your traffic through CloudFlare, as it can cause issues with Discourse sites not working properly.

Yes, there’s a template you can add to your app.yml which will pass the client IP that Cloudflare forwards into Discourse. Add cloudflare.template.yml to the templates block as follows:

templates:
    - "templates/cloudflare.template.yml"

And then rebuild.

I don’t think this is true at all, providing a rule is created to “disable performance” for the Discourse URL so that no extra optimisations or minification interferes with the payload and Brotli is disabled at a domain level there aren’t any real issues.

It does add unnecessary hops from client to server, which can delay requests by a small amount, but otherwise it works fine.

I have translated a lot of strings, btw, will that be lost on rebuild?

Are you contributing to Discourse on Transifex?

There is one, and only one, legit case for running everything through CloudFlare – when your site is at high risk of DDoS and you can’t risk exposing the source IP of your site. There are some other topics here on that, the danger is that the IP can be revealed through some obscure output somewhere so you have to be very sure there are no IP leaks or all is lost.

For people who can’t afford a separate CDN it’s also not a bad way to offload uploads and avatars, but yes otherwise the complexity and disadvantages outweigh any benefits.

Directly in Discourse, Bulgarian translations are just… I already translated “disqus” :smiley: but I just want to know if I rebuild if the internal translations are lost

RE: did it :slight_smile: I ran the script that is in the

templates/cloudflare.template.yml

Added the output to my nginx config, all good now! thank you! :slight_smile:

Heads up Stefan: if you ran the script itself it’ll be overwritten the next time your update Discourse. Be sure to include the template in your app.yml to make sure it is persistent.

If you look near the top of your existing app.yml in /var/discourse/containers/app.yml you’ll see a number of templates. Add Cloudflare the Cloudflare template to that list. Note that YAML is incredible whitespace sensitive, so ensure everything continues to line up.

Sure, added already.

Just want to know if rebuild deletes the local translations

If you did them in the UX through the /admin/customize/text interface, you’re safe.

Perfect, thank you for the information