# Setup Discourse with KeyCDN

**URL:** https://meta.discourse.org/t/setup-discourse-with-keycdn/35807
**Category:** Sysadmins
**Tags:** cdn, how-to
**Created:** [November 19, 2015, 7:05pm UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807 "2015-11-19T19:05:14Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![CodyArsenault](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codyarsenault/32/122092_2.png) [@CodyArsenault](https://meta.discourse.org/u/CodyArsenault)
#### Post date: [November 19, 2015, 7:05pm UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807/1 "2015-11-19T19:05:14Z")

</div>

For those who are using Discourse and are looking to integrate with [KeyCDN](https://www.keycdn.com/), here is a quick step-by-step set up guide.

1. [Login](https://www.keycdn.com/login) or [sign up](https://www.keycdn.com/signup) for a 30 day free trial if you don’t already have a KeyCDN account.

- Create a [Pull Zone](https://www.keycdn.com/support/create-a-pull-zone/) within the KeyCDN dashboard and enter the origin url of your Discourse instance.  

- If you want to use a custom CDN url (e.g `cdn-discourse.yourdomain.com`) you must create a [zonealias](https://www.keycdn.com/support/create-a-zonealias/). Otherwise, you can use the zone url provided by KeyCDN which will look similar to: `http://discourse-1.kxcdn.com`.

- Update your app.yml file by uncommenting the CDN line and adding your custom CDN or zone url:

- Rebuild your Docker container:

- Finally, double check your Page Source to verify that the urls have been modified and reflect the CDN url you have specified in step 4.

---

<div class="post-metadata">

### Author: ![webperf](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/webperf/32/48223_2.png) [@webperf](https://meta.discourse.org/u/webperf)
#### Post date: [November 20, 2015, 7:46am UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807/2 "2015-11-20T07:46:44Z")

</div>

In case you installed Discourse in a subfolder - [Serve Discourse from a subfolder (path prefix) instead of a subdomain](https://meta.discourse.org/t/subfolder-support-with-docker/30507)

Remove those 2 lines from the app.yml config before your rebuild the app:

```
- rm public/uploads
- rm public/backups

```

Otherwise will it remove your existing uploads and backups.

---

<div class="post-metadata">

### Author: ![ljpp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ljpp/32/96506_2.png) [@ljpp](https://meta.discourse.org/u/ljpp)
#### Post date: [March 13, 2018, 9:19am UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807/3 "2018-03-13T09:19:40Z")

</div>

Setting up KeyCDN for Discourse was very easy and simple. So far liking the service.

However, I am unable to enable **Brotli** in KeyCDN zone settings. Their tech support says that when enabling the setting, the system verifies whether the origin support Brotli – this test fails on my standard Discourse 1.9 Docker instances.

I assumed that Discourse does support Brotli compressed assets and snooping the source of Meta supports this. Is this a glitch at KeyCDN (Brotli support is very new) or with Discourse?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 13, 2018, 9:51am UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807/4 "2018-03-13T09:51:22Z")

</div>

KeyCDN works with brotli just fine, be sure to rebuild your container so it has the enable brotli env setting.

---

<div class="post-metadata">

### Author: ![ljpp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ljpp/32/96506_2.png) [@ljpp](https://meta.discourse.org/u/ljpp)
#### Post date: [March 13, 2018, 10:53am UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807/5 "2018-03-13T10:53:31Z")

</div>

Is there a reason why it is not enabled by default (or even included in the .yml)? Risks, downsides?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 13, 2018, 10:59am UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807/6 "2018-03-13T10:59:07Z")

</div>

It is:

> <https://github.com/discourse/discourse_docker/blob/master/image/base/Dockerfile#L7>

@Falco added that magic a while back.

---

<div class="post-metadata">

### Author: ![ljpp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ljpp/32/96506_2.png) [@ljpp](https://meta.discourse.org/u/ljpp)
#### Post date: [March 13, 2018, 11:00am UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807/7 "2018-03-13T11:00:41Z")

</div>

Okay, “a while back” refers to 2.0 development branch, I presume.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 13, 2018, 11:02am UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807/8 "2018-03-13T11:02:04Z")

</div>

Yeah, with the base image you are running, that “stable” thing you enter has no impact on it unless you somehow are running on a custom `base_image`

---

<div class="post-metadata">

### Author: ![ljpp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ljpp/32/96506_2.png) [@ljpp](https://meta.discourse.org/u/ljpp)
#### Post date: [March 13, 2018, 11:04am UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807/9 "2018-03-13T11:04:08Z")

</div>

Now you completely lost me.

Yes, I always use stable, so currently on 1.9. At least according to KeyCDN’s validation my intance is not Brotli enabled.

I added COMPRESS\_BROTLI: 1 and rebuilt one of my instances, and KeyCDN still disagrees – trying to enable Brotli returns an error.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 13, 2018, 11:08am UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807/10 "2018-03-13T11:08:38Z")

</div>

Have you confirmed you are actually not serving brotli, cause my CDN hack means it don’t matter what they say

---

<div class="post-metadata">

### Author: ![ljpp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ljpp/32/96506_2.png) [@ljpp](https://meta.discourse.org/u/ljpp)
#### Post date: [March 13, 2018, 11:12am UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807/11 "2018-03-13T11:12:30Z")

</div>

At least I don’t have references to .br\* assets in the HTML source, like you do here at Meta. I don’t know how KeyCDN validates this, but apparenty my sites fail the test. So does Meta, btw.

> **[Brotli Test - Verify Brotli Compression Support | KeyCDN Tools](https://tools.keycdn.com/brotli-test)**
>
> Test if a server supports the Brotli compression. The Brotli algorithm, which is the successor of Gzip, allows better and faster compression results.

Edit: Looking at a rebuild process, I do see some things Brotli going on, even without the environment variable set. So I guess the assets are indeed generate, but for some reason not good enough for KeyCDN.

---

<div class="post-metadata">

### Author: ![ljpp](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ljpp/32/96506_2.png) [@ljpp](https://meta.discourse.org/u/ljpp)
#### Post date: [March 13, 2018, 3:05pm UTC](https://meta.discourse.org/t/setup-discourse-with-keycdn/35807/12 "2018-03-13T15:05:00Z")

</div>

Well, one thing is verified - KeyCDN has very good support staff. They really drilled into this, for a small-time customer:

> I’ve checked back and discourse is a bit of a special case here. Discourse is using service workers on the client side to do the handling and switch when to use br assets with client-side JavaScript.

> Your pages are already delivering Brotli-encoded content through the CDN as can be seen in the Chrome Dev Tool. (Screenshot)

So @sam’s comment was the real deal. I just could not verify it personally.
