Discourse のために CDN を有効にする

Discourse フォーラムで一般的なアセットへの世界中のアクセスを高速化するために CDN を使用したいということですね? その場合は、すべてを投入して Set up file and image uploads to S3 (Configure an S3 compatible object storage provider for uploads も参照) を利用することを検討するとよいでしょう。

S3 の追加の複雑さや2つの CDN を持つことなく CDN を利用したい場合は、このガイドが役立ちます。CDN は、サーバーがアセットを提供する必要をなくすことで、サーバーの負荷を軽減できます。また、エンドユーザーに近い場所からファイルを配信することで、高速化することもできます。

選択した CDN にサインアップしてください。CDCK/discourse.org は Fastly を使用しており、強く推奨しています。

設定は次のようになります。

注目すべきは主に 3 つの設定です。

  1. オリジンアドレス: 現在フォーラムがある URL、discourse.example.com です。CDN は、最初の要求時にすべてのオリジナルコンテンツをここから取得します。

  2. CNAME: DNS で設定する CDN の「フレンドリーな」名前です。例: discourse-cdn.example.com

  3. CDN URL: キャッシュされた CDN アセットが CDN の世界中に分散されたサーバーのネットワーク経由で配信される場所の「アンフレンドリーな」名前です。637763234.cdn-provider.com のようになります。

次のように、CNAME を CDN URL にマッピングするように DNS を編集する必要があります。

discourse-cdn.example.com IN CNAME 637763234.cdn-provider.com

(DNS を編集したら、伝播にしばらく時間をかけてください。)

Discourse 側の設定はかなり簡単です。app.yml の CDN 行のコメントを解除し、DNS で設定した CNAME で更新します。

    ## この Discourse インスタンスの http または https CDN アドレス (プル用に設定)
    DISCOURSE_CDN_URL: https://discourse-cdn.example.com

:warning: CDN URL にはプロトコル (https:// または http://) を含める必要があります。 プロトコル相対 URL ( // で始まるもの) はサポートされなくなり、コンテナのビルドが中止されます。

(この行が app.yml にない場合は、他の DISCOURSE_ 変数の下に挿入してください)

app.yml の他の変更と同様に、変更を反映するためにコンテナを再構築する必要があります。

./launcher rebuild app

再構築が完了したら、ブラウザで Discourse インスタンスを参照してください。ソースを表示して「cdn」を検索すると、ウェブサイトのアセットが CDN から配信されていることが確認できます。

<script src="https://discourse-cdn.codinghorror.com/assets/preload_store-4ea79c2f435becca86ac97a9c038f9c7.js"></script>
<script src="https://discourse-cdn.codinghorror.com/assets/locales/en-7084a68855205a9128245d2d0ce94ed9.js"></script>

このトピックでは、静的アセットのアクセラレーションというより一般的なシナリオについて説明しています。動的アセットと静的アセットの両方のサイト全体の CDN アクセラレーション (Cloudflare によって提供されるようなもの) については、こちらのトピックを参照してください。Cloudflare は従来の CDN とは異なる動作をするため、Cloudflare の議論にはこのトピックは適していません。

動作が報告されているその他の CDN には次のようなものがあります。

「いいね!」 43
Full site CDN acceleration for Discourse
Azure Backup/CDN Integration
Downloading remote images disabled due to disk space
How do I change the legacy CDN URLs of images in posts?
Add a new site (android) 'was not found'
CloudFront not caching static files
How to enable AWS CDN to accelerate the discourse service
Cloudfront cdn with discourse?
How to add AWS Cloudfront as a Discourse CDN
How to solve super slow loading time for site?
Varnish config for discourse
S3 image bandwidth costs are getting annoying
Discourse load balancer encounters problems, hoping to help
Is Hetzner Object Storage and Bunny CDN Supported?
I can't login to admin after backup due to Cloudflare
How to install discourse without ssl?
How to add AWS Cloudfront as a Discourse CDN
Conserving unicorns by serving images with nginx?
Is Hetzner Object Storage and Bunny CDN Supported?
Optimizing Site For Speed - How To Improve?
Latest commits in v3.3.0.beta3-dev seems to break Discourse
How to make Discourse faster for image-heavy communities?
Using Discourse with Cloudflare: Best Practices
Minimum server size based on backup?
Understanding Uploads, Images, and Attachments
Uploads Subdomain For Cloudflare
Discourse & Cloudflare
Mobile app URL issues
Forum does not work
Should I load third-party libraries from vendor or cdn?
Forum not working after configuring CDN (ERR_CERT_COMMON_NAME_INVALID)
Blank login and signup page
My discourse speed is very slow
MKJ's Opinionated Discourse Deployment Configuration
How might we better structure #howto?
Change image folder to symlinked folder