CloudFront speichert statische Dateien nicht im Cache

Hallo.

Ich habe eine Discourse-Installation der Version v2.3.0.beta2 auf AWS eingerichtet.

Dieser Anhang zeigt, wie ich sie bereitgestellt habe. Ich verwende das offizielle Docker-Image-Installation auf jeder Instanz der Auto-Scaling-Gruppe.

Ich habe zwei CloudFront-Distributionen:
Eine (cdn.civicxclub.com), die auf die S3-Buckets zeigt, um hochgeladene Bilder direkt über das CDN auszuliefern. DAS FUNKTIONIERT.
Die andere (civicxclub.com), die auf den Load Balancer zeigt, um die App und alle statischen Dateien davon auszuliefern. DAS FUNKTIONIERT NICHT.

So sieht meine Konfiguration für die Verhaltensweisen aus:

Die Standardkonfiguration hat die Option „Cache basierend auf ausgewählten Anfrage-Headern" auf Alle gesetzt, um kein Caching vom Backend zu ermöglichen.
Alle anderen haben „Cache basierend auf ausgewählten Anfrage-Headern" auf Whitelist gesetzt, und ich habe die Header Host, Origin und Referer in die Whitelist aufgenommen.

Wenn ich über den Browser auf die Webseite zugreife und die Header beispielsweise eines Avatars prüfe, steht dort immer „Miss from Cloudfront". Wenn ich jedoch die Datei zweimal direkt im Browser aufrufe, steht dort „Hit from Cloudfront". Das Caching funktioniert also, aber nicht beim Laden von Dateien über die Forum-Webseite.

Die Discourse-CDN-Variable ist wie folgt gesetzt:

  DISCOURSE_CDN_URL: https://civicxclub.com

Haben Sie irgendwelche Ideen?

Vielen Dank im Voraus, viele Grüße.

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 „Gefällt mir“

Nobody said anything about cloudflare. Read more closely?

1 „Gefällt mir“

Maybe I mis-read title as cloudflare.

2 „Gefällt mir“

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 „Gefällt mir“