The user soke is troubleshooting CloudFront caching issues for static files in a Discourse v2.3.0.beta2 deployment on AWS. They have two CloudFront distributions: one for S3-hosted uploads (working) and another for the web app (not caching static files properly). Despite CloudFront showing ‘Hit’ on repeated requests, files loaded from the forum page return ‘Miss’, indicating caching isn’t working as expected. The DISCOURSE_CDN_URL is set to https://civicxclub.com, but itsbhanusharma suggests using a dedicated CDN URL instead of the server name. Falco reinforces this, advising a separate CDN URL and referencing the official guide here. soke questions how to serve static content from a CDN when files are stored on the server, while codinghorror corrects a misinterpretation about Cloudflare. The discussion highlights configuration issues related to CDN setup and header settings in CloudFront.
I have 2 CloudFront distributions
One (cdn.civicxclub.com) pointing to the S3 buckets for serving the uploaded images directly from the CDN. THIS WORKS.
The other one (civicxclub.com) pointing to the balancer, in order to serve the app and all the static files from it. THIS DOESN’T WORK
This is the behaviours configuration that I have:
The default one has Cache Based on Selected Request Headers option set to All in order to not allow caching from the backend.
All the others has Cache Based on Selected Request Headers set to *Whitelist and I whitelist Host, Origin and Referer headers.
When I access the web from the browser and inspect headers from for example an avatar It always says Miss from cloudfront, but when I access the file twice directly from the brownser, it says Hit from cloudfront, so the caching is working, but not when loading files from the forum web page.
How can I then serve avatars, css and js files from this CDN if they are stored on the server??
I’ve tried to use the cdn.civicxclub.com url which is mapping to the S3 bucket and add all the behaviours related to discourse static content, and it failed.