# Assets not serving from CDN in latest update

**URL:** https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705
**Category:** Support
**Created:** [February 5, 2020, 10:56am UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705 "2020-02-05T10:56:00Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![eatcodetravel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eatcodetravel/32/94385_2.png) [@eatcodetravel](https://meta.discourse.org/u/eatcodetravel)
#### Post date: [February 5, 2020, 10:56am UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/1 "2020-02-05T10:56:00Z")

</div>

Hello!

I couldn’t figure out why in the latest update our installation stopped serving assets from the CDN. We are using Cloudfront and it was working good to serve both uploads and assets, but it looks like in the latest update assets are serving from the server instead.

 ![image](https://global.discourse-cdn.com/meta/original/3X/0/9/096155d097c264434deee6869c3f45e481486af7.png)

Another issue we are having is if we pass the variable `DISCOURSE_CDN_URL`, Discourse starts requesting assets that are not being generated or uploaded by the `s3:upload_assets` task (stylesheets for example). This breaks completely the site with a white page. This post mentions something similar.

> [@DISCOURSE\_CDN\_URL breaks rebuild/restore](https://meta.discourse.org/t/discourse-cdn-url-breaks-rebuild-restore/136844):
>
> EDIT: Well, it took me 18 hours, but it seems that defining DISCOURSE\_CDN\_URL keeps (at least) this site from rebuilding and/or functioning after a restore. I guess the next thing to test is doing a build without DISCOURSE\_CDN\_URL and then cranking up the container with the ENV var set. What I knew before I had this problem yesterday but thought it went away, but it turns out that I restored a month-old database. Restoring the recent database kills the site. I was able to build the site from s…

Any help would be greatly appreciated.

Thanks!

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 6, 2020, 10:37am UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/2 "2020-02-06T10:37:37Z")

</div>

Is this a new bug @falco? Did we break something here?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [February 6, 2020, 3:41pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/3 "2020-02-06T15:41:59Z")

</div>

@eatcodetravel we need a lot more detail in order to help you in any way.

What are the exact values of the settings and environment variables related to S3 and CDN?

---

<div class="post-metadata">

### Author: ![eatcodetravel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eatcodetravel/32/94385_2.png) [@eatcodetravel](https://meta.discourse.org/u/eatcodetravel)
#### Post date: [February 6, 2020, 4:18pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/4 "2020-02-06T16:18:05Z")

</div>

@Falco sure what information do you need? Our setup is open source, and here are the settings we are running.

- web.yml container template [https://github.com/debtcollective/infra/blob/master/modules/services/discourse/web.yml](https://github.com/debtcollective/infra/blob/master/modules/services/discourse/web.yml)
- settings.yml - we apply this in the first run [https://github.com/debtcollective/infra/blob/master/modules/services/discourse/settings.yml](https://github.com/debtcollective/infra/blob/master/modules/services/discourse/settings.yml)
- ec2 instance setup [https://github.com/debtcollective/infra/blob/master/modules/services/discourse/cloud-config.yml](https://github.com/debtcollective/infra/blob/master/modules/services/discourse/cloud-config.yml)

I removed the `DISCOURSE_CDN_URL` which is was set to the same value as `DISCOURSE_S3_CDN_URL` because that broke the site (it was trying to pull assets that didn’t exist on S3).

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 6, 2020, 4:22pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/5 "2020-02-06T16:22:51Z")

</div>

Looking back at the site that I was having trouble with, it appears that I’d left out the `https://` on the CDN URL I was using. I’m not clear how it was that it had ever worked, or, if it hadn’t ever worked, how I hadn’t noticed that when I added the broken value.

@eatcodetravel, you of course need to redact SMTP passwords and S3 keys, but I think you’ll need to share at least the CDN values for anyone to be able to make any guesses what the problem might be.

---

<div class="post-metadata">

### Author: ![eatcodetravel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eatcodetravel/32/94385_2.png) [@eatcodetravel](https://meta.discourse.org/u/eatcodetravel)
#### Post date: [February 6, 2020, 4:27pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/6 "2020-02-06T16:27:25Z")

</div>

Sure let me write these here,I think just the CDN\_URL since the others are validated via the aws sdk

```plaintext
DISCOURSE_S3_CDN_URL: 'https://community-cdn-prod.debtcollective.org'
DISCOURSE_S3_REGION: 'us-west-1'

```

`DISCOURSE_CDN_URL` was set to ‘[https://community-cdn-prod.debtcollective.org](https://community-cdn-prod.debtcollective.org)’ too before I removed it

Nothing mayor changed in our setup, just migrated to a bigger ec2 machine.

Also, let me know if you need more info @Falco, happy to answer your questions

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [February 6, 2020, 4:47pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/7 "2020-02-06T16:47:17Z")

</div>

So you are currently using a `S3 CDN` but not the normal `CDN`. I’m not sure that is a supported setup…

Other 3 combinations work fine for sure:

1. No CDN
2. Just `DISCOURSE_CDN_URL`
3. Both `DISCOURSE_CDN_URL` and `DISCOURSE_S3_CDN_URL`.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 6, 2020, 4:49pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/8 "2020-02-06T16:49:46Z")

</div>

> [@Falco](#):
>
> o you are currently using a `S3 CDN` but not the normal `CDN` . I’m not sure that is a supported setup

I think that might explain some other CDN issues that I’ve had in the past.

---

<div class="post-metadata">

### Author: ![eatcodetravel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eatcodetravel/32/94385_2.png) [@eatcodetravel](https://meta.discourse.org/u/eatcodetravel)
#### Post date: [February 6, 2020, 4:53pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/9 "2020-02-06T16:53:57Z")

</div>

> [@Falco](#):
>
> So you are currently using a `S3 CDN` but not the normal `CDN` .

Yeah, I had to remove `DISCOURSE_CDN_URL`, it started asking for assets that are not being uploaded to S3 by the `rake s3:upload_assets` task and this breaks the site completely. Maybe this was the part that changed and we need to update `rake s3:upload_assets` to work again correctly

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [February 6, 2020, 4:57pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/10 "2020-02-06T16:57:46Z")

</div>

Yeah, using the same CDN URL for both `DISCOURSE_CDN_URL` and `DISCOURSE_S3_CDN_URL` can be done, but it requires a **lot** of login in the CDN to use the correct source for each asset based on the URL. For example, CSS comes from the app, JS from S3 and this is just one case, we have dozens.

So the expectation is that you set both, where the `DISCOURSE_CDN_URL` is a “proxy” to your web app, and `DISCOURSE_S3_CDN_URL` is a proxy to your object storage bucket.

---

<div class="post-metadata">

### Author: ![eatcodetravel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eatcodetravel/32/94385_2.png) [@eatcodetravel](https://meta.discourse.org/u/eatcodetravel)
#### Post date: [February 6, 2020, 5:18pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/12 "2020-02-06T17:18:19Z")

</div>

Oh ok, is this something that changed recently? I’m not sure if Cloudfront supports being a reserve proxy to our app instead of an S3 bucket.

I see you are using Cloudfront in meta, is there anything special you do to run it or Discourse itself takes care of everything?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [February 6, 2020, 5:21pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/13 "2020-02-06T17:21:34Z")

</div>

If you inspect this page you will see that we we have two different Cloudfront URLs, so we use what I said above, two distributions, one for the normal CDN and another for S3.

The problem from the title of the OP is this: CSS come from the app and JS from S3. You need a CDN that is aware of where every single asset is coming from and can reach the necessary place or two CDNs. That is why we have two different settings after all.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [February 6, 2020, 5:30pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/15 "2020-02-06T17:30:29Z")

</div>

> [@Falco](#):
>
> So the expectation is that you set both,

Though this totally makes sense now that I understand it, I’m not sure that this is documented. And you’re likely to get in trouble (at least I did!), as the move-uploads-to-s3 rake task requires that you have an s3\_cdn. This explains why several times I’ve tried to move stuff to S3 and ended up giving up.

I think it’d be nice if there were some “Dude, you can’t have an S3 CDN without an asset CDN warning somewhere.”

---

<div class="post-metadata">

### Author: ![eatcodetravel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eatcodetravel/32/94385_2.png) [@eatcodetravel](https://meta.discourse.org/u/eatcodetravel)
#### Post date: [February 6, 2020, 5:35pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/16 "2020-02-06T17:35:41Z")

</div>

Ok now I understand what you are saying now, didn’t know this was required. May I ask why CSS needs to come from the app? Why we can’t upload it via the `rake s3:upload_assets` task?

I’ll make some research on how to achieve this on Cloudfront and put my findings/blockers here.

Thanks @Falco, this was really helpful

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [February 6, 2020, 5:38pm UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/17 "2020-02-06T17:38:12Z")

</div>

> [@pfaffman](#):
>
> I think it’d be nice if there were some “Dude, you can’t have an S3 CDN without an asset CDN warning somewhere.”

Well, I may be explaining this badly. You can. But it is fiddly as your topics and this one on it shows.

The site from @eatcodetravel is running right now with just S3\_CDN set, but then you get into a weird state where CSS (which blocks rendering) is served from your server while images in posts aren’t, which makes no sense.

> [@eatcodetravel](#):
>
> May I ask why CSS needs to come from the app? Why we can’t upload it via the `rake s3:upload_assets` task?

Because Admin \> Customize is a thing. People can change CSS on the admin panel. Custom JS snippets living in themes are also served from the app AFAIK.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 7, 2020, 4:25am UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/18 "2020-02-07T04:25:16Z")

</div>

> [@pfaffman](#):
>
> Though this totally makes sense now that I understand it, I’m not sure that this is documented

Can we somehow document this better @falco? Maybe even in a “here be 🐉s” way?

---

<div class="post-metadata">

### Author: ![eatcodetravel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eatcodetravel/32/94385_2.png) [@eatcodetravel](https://meta.discourse.org/u/eatcodetravel)
#### Post date: [February 7, 2020, 5:12am UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/19 "2020-02-07T05:12:27Z")

</div>

I ended up fixing this by providing a second Cloudfront distribution that points to the web server, and keep the other one just for S3. Thank you @Falco for the feedback, but I agree this needs to be documented a bit better.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [March 8, 2020, 5:13am UTC](https://meta.discourse.org/t/assets-not-serving-from-cdn-in-latest-update/140705/21 "2020-03-08T05:13:44Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
