CloudFront not caching static files

Hi.

I have setup a discourse version v2.3.0.beta2 installation on AWS.

This attachment shows how I have it deployed. I’m using the official docker image installation on each instance of the auto scaling group

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.

The Discourse CDN Variable is set:

  DISCOURSE_CDN_URL: https://civicxclub.com

Any thoughts?

Thanks in advance, regards.

You’re doing it wrong!

You need to split the container into Data and Web or you can use RDS for Postgresql to host data and load-balance among the web containers.

Also, It is not recommended to use cloudflare optimizations as they cause many issues.

And You need to set up your cloudfront URL in the discourse CDN field not the name of the server.

I deploy the web only container on the EC2 servers. The database is outside, on an RDS instance, as well as the Redis.

I have a CloudFront for uploads (the setting is on admin panel, and it works) and other for serving the whole webpage.

Now, I’m looking into the static headers, and it seems to work, some files yes, some don’t.

DISCOURSE_CDN_URL should be different from the DISCOURSE_HOSTNAME. Use a dedicated URL for the CDN.

Also, in our experience making all traffic go into the cloudfront tunnel increases the latency.

4 Likes

Nobody said anything about cloudflare. Read more closely?

1 Like

Maybe I mis-read title as cloudflare.

2 Likes

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.

Please read our CDN guide:

3 Likes