CloudFront não está armazenando em cache arquivos estáticos

Olá.

Configurei uma instalação do Discourse versão v2.3.0.beta2 na AWS.

Este anexo mostra como fiz a implantação. Estou usando a instalação oficial da imagem Docker em cada instância do grupo de autoescalabilidade.

Tenho duas distribuições do CloudFront:
Uma (cdn.civicxclub.com) apontando para os buckets S3 para servir as imagens carregadas diretamente pela CDN. ISSO FUNCIONA.
A outra (civicxclub.com) apontando para o balanceador, a fim de servir o aplicativo e todos os arquivos estáticos a partir dele. ISSO NÃO FUNCIONA.

Esta é a configuração de comportamentos que tenho:

O padrão tem a opção “Cache baseado em cabeçalhos de solicitação selecionados” definida como Todos, para não permitir o cache a partir do backend.
Todos os outros têm “Cache baseado em cabeçalhos de solicitação selecionados” definido como Lista branca, e eu incluo na lista branca os cabeçalhos Host, Origin e Referer.

Quando acesso a web pelo navegador e inspeciono os cabeçalhos de, por exemplo, um avatar, ele sempre diz “Miss from cloudfront”, mas quando acesso o arquivo duas vezes diretamente pelo navegador, ele diz “Hit from cloudfront”. Portanto, o cache está funcionando, mas não ao carregar arquivos da página do fórum.

A variável DISCOURSE_CDN_URL está definida:

  DISCOURSE_CDN_URL: https://civicxclub.com

Alguma ideia?

Obrigado antecipadamente, cumprimentos.

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 curtidas

Nobody said anything about cloudflare. Read more closely?

1 curtida

Maybe I mis-read title as cloudflare.

2 curtidas

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 curtidas