Full site CDN acceleration for Discourse

I have a question concerning CDN technology.

Am I right that cdn can only cache the files in my site and can’t cache hotlinked files from another site?

I store catalogue files (mps and pictures) on another server and hotlink them on my Discourse site. Am I right that such files won’t be cached by cdn? Is there a way to cache the hotlinked files too?

Unless you tell discourse not to, it will pull those remote images to its own image store. The below assumes you turned that off.

You should put that site behind CDN and then share the CDN url to discourse.

If you put a CDN in front of your image site but share the origin url to discourse, You can use a built in feature to replace the origin url with the CDN url .

2 Likes

Am I right, that if I activate the CDN feature in Discourse and switch off saving the origin to Discourse, the cdn service will cache these external files and Discourse will replace all the links to files hotlinked from another site?

I doubt that can caches external files hotlinked from other sites. Can anybody approve it?

FYI - I’ve posted a new thread on how to setup full site CDN acceleration (and SSL termination) using AWS Cloudfront here (link below). There be dragons here - so tread lightly.

1 Like

Is that still required when the error Reason: CORS header ‘Access-Control-Allow-Origin’ missing happens?

I can’t find anything that uses that variable in the Github:


Edit: the settings comment still say it’s needed, and it does work after that. So I’ll just accept :slight_smile:

At present days 2023, does the below four rules still needed to follow strictly? For example, if I were to use Akamai, which is designed to make the main domain name with its CDN accelerating. Does any one has a distilled configuration of below rules, such as should message bus and long polling still need to request to origin? Where these settings should go? long polling base url seems is removed from admin dashboard?

2 Likes

There are some advanced knobs that let you serve Message Bus requests from a different domain. It is very complex though.

1 Like

So “long polling base url” has to be set through Rails console. As it has been removed from admin dashboard. I must miss the reason posted in anywhere before why it’s removed if the setting still required to enable the site working well in Full site CDN mode.

Likewise, DISCOURSE_ENABLE_CORS: true has to be set in app.yml.

You should set it with an env variable (DISCOURSE_LONG_POLLING_BASE_URL) in your app.yml. It’s hidden because very few people need to set it and it’s assumed that if you’re doing that you know what you’re doing.

1 Like

Thanks, @pfaffman! I should have known all these capitalised variable should go into app.yml.
So, what the use cases of message-bus will take effect? For example, a reply to a post causing notification etc? I would do a use cases testing to ensure whether or not message-bus in my site working as expected w/o DISCOURSE_LONG_POLLING_BASE_URL set.

Hi,
Is “long polling base url” removed from admin dashboard? Or can this setting be done through rails console?

long_polling_base_url is a hidden site setting, but can be set from the rails console if you aren’t using an environment variable in your app.yml:

3 Likes

This list definitely give more insights of the Discourse.
I’ve setup the CDN with my website, it has reached edge caches, however haven’t experienced message-bus issue with its response headers with, but still doesn’t feel solid. Neither set CORS settings.

Cache-Control: must-revalidate, private, max-age=0

Hi,
I posted my question in another thread Full Site CDN Using AWS CloudFront - #2 by Hyan. I did the same config and leave #DISCOURSE_CDN_URL: https://discourse-cdn.example.com unchanged. Can I set this to the same URL of the website? For example, http://forum.example.com. Otherwise, there’re assets URL in relative path without domain name.
Appreciated if @sam or @pfaffman give a hint.

I don’t recommend using Cloudflare as a CDN. Some people do. Perhaps they can help.

EDIT: Oh, sorry. This is “Full site CDN…” Maybe I shouldn’t be contributing here.

No, I use the Akamai CDN, which supports cache dynamic content.
From the first post in this thread, it looks I should set the DISCOURSE_CDN_URL as non full site CDN does, though the URL is the same as the website URL. I am just not sure if setting it causes my site broken and other irreversible results, in the end I have to reinstall the software from scratch. In this post Full Site CDN Using AWS CloudFront, the author doesn’t set and leave DISCOURSE_CDN_URL unchanged, and it doesn’t require a separate URL to serve message-bus/long-polling. I use this solution and my website is running well so far. The only drawback of the solution is that there’re many relative URL (no base URL, as DISCOURSE_CDN_URL value is empty) presenting in the page source, which makes it look not a production level website.

Following up my questions, I found a similar post that is that I’m asking in this post CloudFront not caching static files - #4 by Falco
Appreciated @Falco answer, in this Full site CDN setup, can I set the DISCOURSE_CDN_URL the same as DISCOURSE_HOSTNAME? As I assume the Full site CDN means CDN accelerate the URL of hostname which makes the DISCOURSE_CDN_URL the same as DISCOURSE_HOSTNAME. But here’s no a decent document about this in meta.