CloudFront no está almacenando en caché archivos estáticos

Hola.

He configurado una instalación de Discourse versión v2.3.0.beta2 en AWS.

Este adjunto muestra cómo lo he desplegado. Estoy utilizando la instalación oficial de la imagen de Docker en cada instancia del grupo de autoescalado.

Tengo 2 distribuciones de CloudFront:
Una (cdn.civicxclub.com) apuntando a los buckets de S3 para servir las imágenes cargadas directamente desde la CDN. ESTO FUNCIONA.
La otra (civicxclub.com) apuntando al balanceador, para servir la aplicación y todos los archivos estáticos desde él. ESTO NO FUNCIONA.

Esta es la configuración de comportamientos que tengo:

La configuración predeterminada tiene la opción “Cache Based on Selected Request Headers” establecida en All para no permitir la caché desde el backend.
Todas las demás tienen “Cache Based on Selected Request Headers” establecida en Whitelist y he puesto en lista blanca las cabeceras Host, Origin y Referer.

Cuando accedo a la web desde el navegador e inspecciono las cabeceras de, por ejemplo, un avatar, siempre dice “Miss from cloudfront”, pero cuando accedo al archivo dos veces directamente desde el navegador, dice “Hit from cloudfront”, por lo que la caché funciona, pero no al cargar archivos desde la página web del foro.

La variable DISCOURSE_CDN_URL está configurada:

  DISCOURSE_CDN_URL: https://civicxclub.com

¿Alguna idea?

Gracias de antemano, saludos.

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 Me gusta

Nobody said anything about cloudflare. Read more closely?

1 me gusta

Maybe I mis-read title as cloudflare.

2 Me gusta

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 Me gusta