CloudFront で静的ファイルがキャッシュされない

こんにちは。

AWS に Discourse のバージョン v2.3.0.beta2 をセットアップしました。

この添付画像は、私のデプロイ構成を示しています。各オートスケーリンググループのインスタンスには、公式の Docker イメージを使用してインストールしています。

CloudFront ディストリビューションは 2 つあります。
1 つ目 (cdn.civicxclub.com) は、アップロードされた画像を CDN から直接配信するために S3 バケットを指しています。これは動作しています。
もう 1 つ (civicxclub.com) は、アプリとすべての静的ファイルを配信するためにロードバランサーを指しています。これは動作していません。

現在設定しているビヘイビアの設定は以下の通りです。

デフォルトのビヘイビアでは、バックエンドからのキャッシュを許可しないよう、「キャッシュ基準」を「すべてのリクエストヘッダーに基づいて」に設定しています。
他のすべてのビヘイビアでは、「キャッシュ基準」を「ホワイトリスト」に設定し、「Host」「Origin」「Referer」ヘッダーをホワイトリストに登録しています。

ブラウザからウェブサイトにアクセスし、例えばアバターのヘッダーを検査すると、常に「CloudFront Miss」と表示されます。しかし、ブラウザからファイルを 2 回直接アクセスすると「CloudFront Hit」と表示されます。つまり、キャッシュは機能していますが、フォーラムのウェブページからファイルを読み込む際には機能していないようです。

Discourse の CDN 変数は以下のように設定されています。

  DISCOURSE_CDN_URL: https://civicxclub.com

ご助言いただけますでしょうか。

よろしくお願いいたします。

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

Nobody said anything about cloudflare. Read more closely?

「いいね!」 1

Maybe I mis-read title as cloudflare.

「いいね!」 2

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