تفعيل شبكة توصيل محتوى (CDN) لـ Discourse الخاص بك

إذًا، أنت ترغب في استخدام شبكة توصيل محتوى (CDN) لتسريع الوصول العالمي إلى الأصول المشتركة في منتدى Discourse الخاص بك؟ قد ترغب في الالتزام بالكامل والانتقال إلى Set up file and image uploads to S3 (انظر أيضًا Configure an S3 compatible object storage provider for uploads).

إذا كنت تريد شبكة توصيل محتوى (CDN) دون التعقيد الإضافي لـ S3 ووجود شبكتي CDN، فهذا هو الدليل المناسب لك. ستقلل شبكة توصيل المحتوى (CDN) بعض الحمل عن خادمك عن طريق السماح لشبكة توصيل المحتوى (CDN) بخدمة تلك الأصول حتى لا يضطر الخادم إلى ذلك. كما يمكنها تسريع الأمور عن طريق توصيل الملفات من موقع أقرب إلى المستخدم النهائي.

سجّل لدى شبكة توصيل المحتوى (CDN) التي تختارها - لقد استخدمت CDCK/discourse.org وتوصي بشدة بـ Fastly.

سيبدو التكوين شيئًا كهذا:

ما تبحث عنه هو ثلاثة إعدادات رئيسية:

  1. عنوان المصدر (origin address)، وهو عنوان URL حيث يقع منتدىك حاليًا discourse.example.com. هذا هو المكان الذي ستسحب منه شبكة توصيل المحتوى (CDN) جميع محتوياتها الأصلية عند الطلب الأول.

  2. اسم CNAME (CNAME)، وهو الاسم “الودي” لشبكة توصيل المحتوى (CDN) التي ستقوم بإعدادها في نظام أسماء النطاقات (DNS) الخاص بك، على سبيل المثال discourse-cdn.example.com

  3. عنوان URL لشبكة توصيل المحتوى (CDN URL)، وهو الاسم “غير الودي” للمكان الذي ستأتي منه أصول شبكة توصيل المحتوى (CDN) المخزنة مؤقتًا عبر شبكة الخوادم الموزعة عالميًا لشبكة توصيل المحتوى (CDN). سيبدو كـ 637763234.cdn-provider.com

ستحتاج إلى تعديل نظام أسماء النطاقات (DNS) الخاص بك لربط اسم CNAME بعنوان URL لشبكة توصيل المحتوى (CDN)، كالتالي:

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

(بمجرد تعديل نظام أسماء النطاقات (DNS)، امنحه بعض الوقت للانتشار.)

الجزء الفعلي الخاص بـ Discourse من الإعداد بسيط إلى حد ما. قم بإلغاء التعليق على سطر شبكة توصيل المحتوى (CDN) في ملف app.yml الخاص بك وقم بتحديثه باسم CNAME الذي قمت بإعداده للتو في نظام أسماء النطاقات (DNS) الخاص بك:

    ## عنوان http أو https لشبكة CDN لهذا المثيل من Discourse (تم التكوين للسحب)
    DISCOURSE_CDN_URL: https://discourse-cdn.example.com

:warning: يجب أن يتضمن عنوان URL لشبكة توصيل المحتوى (CDN) بروتوكول (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.

شبكات توصيل محتوى (CDNs) أخرى تم الإبلاغ عن عملها تشمل:

43 إعجابًا

I’m sorry guys, I’m trying to figure out how to do this, and I’m drawing a blank. I’ve tried to follow your instructions, but I think the Fastly site must have changed since you created the screenshot, because I can’t find where to enter in the details you’ve presented.

:confused: :confounded:

Minor update - this is the screen I get when I trying to use the service

It doesn’t match up with your example, so I don’t know what goes where.

Fastly is more sophisticated than the general CDN it supports accelerating both dynamic and static content.

To configure.

  1. Plug in the IP address of your Discourse web server in “Server Address”
  2. Plug in your desired domain name in “Domain name”
  3. Point your DNS CNAME for your domain at global.prod.fastly.net per: http://docs.fastly.com/guides/getting-started/cname-instructions-for-most-providers

That is it you should be done, no changes needed on Discourse side.

7 إعجابات

I wonder how to deal with CDN provider does not support https…

There is a cloud storage provider can just acted as CDN. But their spider don’t like SSL. There are APIs for upload assets. I would think the easiest way is to write a plugin to monitor public folder and upload them instantly…

That sounds like a push CDN to me, which was supported in the past but not currently.

This should also work with other CDNs? Like S3?

S3 is not a CDN, but it should work with Amazon CloudFront and any other Pull compatible CDN.

5 إعجابات

If you want an inexpensive CDN, I think MaxCDN might be what you’re looking for. It is a pull-compatible CDN.

However, going to Fastly’s website from a quick google search led me to Fastly’s pricing page in a snap.

MaxCDN goes by a somewhat different pay model (as far as I can see in comparing with Fastly) which is easier to budget with.

إعجاب واحد (1)

I’m new to Discourse and I’ve been trying to configure it with Cloudflare. This tutorial focuses on fastly. I have used Cloudflare on my Wordpress sites in the past and it was quite simple. Typically, Cloudflare scans your website and all you have to do is change your DNS to what Cloudflare provides. My question is… do the same steps I just mentioned apply to discourse? If yes… what so I do with the CDN URL in app.yml? Thanks guys.

إعجاب واحد (1)

You do not have to spend time designating which files to cache. CloudFlare’s technology builds the cache for you based on your traffic and what objects on your site are safe to serve from the edge.

Just be sure you do not enable any JavaScript weirdness / modifications in CloudFlare, as it will break the crap out of Discourse if you do.

8 إعجابات

Anyone have any experience with Cachefly?

They’re running a pay-as-you-go plan with no minimum spend, which seems to be the only one of their peers, since Fastly has a minimum $50/mo spend requirement. https://www.cachefly.com/plans-pricing/pay-as-you-go-cdn/

I’ve heard their name often before and I think they’re up there in the top tier CDN? Just checking others’ experience first…

Cachefly are good, have never used them but heard plenty good things

إعجابَين (2)

Does anyone have any experience in using KeyCDN with Discourse?

They support HTTP/2, have 22 PoPs, and are amongst the cheapest CDN on the market (starting $0.04/GB). If all works well with Discourse it would definitely be something worth looking into.

Yes, I using KeyCDN on my discourse: http://reactvn.org/. It’s working perfectly.

These are the steps to use KEYCDN:

  1. Register [KEYCDN] 1 account: Fill in your e-mail can register, you can using without having to recharge.

  2. Create a pull zone: https://www.keycdn.com/support/create-a-pull-zone/

  3. Create a Zonealias: https://www.keycdn.com/support/create-a-zonealias/

  4. Config Discourse: Modify app.yml, DISCOURSE_CDN_URL point to your CDN URL or an alias. Enable a CDN for your Discourse

7 إعجابات

Any one knows how to configure with http://www.coralcdn.org/ ?

Is there any way to change the CDN url without having to rebuild the Docker container or is updating the app.yml and rebuilding currently the only way?

No, that is the only way.

إعجاب واحد (1)

Why not use CloudFlare? They don’t charge for bandwidth at all. (Plus a bunch of other features, like free SSL).

3 إعجابات

You can use Cloudflare along with another CDN. You don’t get full CDN advantages with Cloudflare unless you pay, and for serving up lots of images, attachments, or other media you’ll want a dedicated CDN to reduce the server load.

after enable CDN, i can not visit my site any more.

I have this error in my log:

nginx: [emerg] host not found in upstream "avatars.discourse.org" in /etc/nginx/conf.d/discourse.conf:247