CloudFront non memorizza nella cache i file statici

Ciao.

Ho configurato un’installazione di Discourse versione v2.3.0.beta2 su AWS.

Questo allegato mostra come l’ho distribuita. Sto utilizzando l’installazione ufficiale dell’immagine Docker su ogni istanza del gruppo di auto-scaling.

Ho 2 distribuzioni CloudFront:
Una (cdn.civicxclub.com) che punta ai bucket S3 per servire direttamente le immagini caricate tramite CDN. QUESTO FUNZIONA.
L’altra (civicxclub.com) che punta al bilanciatore di carico, per servire l’applicazione e tutti i file statici. QUESTO NON FUNZIONA.
Questa è la configurazione dei comportamenti che ho impostato:

Quello predefinito ha l’opzione “Cache basata su intestazioni di richiesta selezionate” impostata su Tutte, per non consentire la cache dal backend.
Tutti gli altri hanno “Cache basata su intestazioni di richiesta selezionate” impostata su Whitelist e ho inserito nella whitelist le intestazioni Host, Origin e Referer.

Quando accedo al sito dal browser ed esamino le intestazioni, ad esempio per un avatar, viene sempre indicato “Miss da CloudFront”, ma quando accedo al file due volte direttamente dal browser, viene indicato “Hit da CloudFront”. Quindi la cache funziona, ma non quando si caricano i file dalla pagina web del forum.

La variabile CDN di Discourse è impostata così:

  DISCOURSE_CDN_URL: https://civicxclub.com

Qualche idea?

Grazie in anticipo, saluti.

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 Mi Piace

Nobody said anything about cloudflare. Read more closely?

1 Mi Piace

Maybe I mis-read title as cloudflare.

2 Mi Piace

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 Mi Piace