# CDN unable to access assets from origin

**URL:** https://meta.discourse.org/t/cdn-unable-to-access-assets-from-origin/72560
**Category:** Support
**Created:** [October 22, 2017, 10:58am UTC](https://meta.discourse.org/t/cdn-unable-to-access-assets-from-origin/72560 "2017-10-22T10:58:34Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![disc](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@disc](https://meta.discourse.org/u/disc)
#### Post date: [October 22, 2017, 10:58am UTC](https://meta.discourse.org/t/cdn-unable-to-access-assets-from-origin/72560/1 "2017-10-22T10:58:34Z")

</div>

“./launcher rebuild app” generates brotli-compressed asset files with file extension “.js.br”. However, when “view source” in the browser, the asset files all have extension “.br.js”. The mismatch of file names causes 404s for CDN, as a result the browser can’t download those files either.

For example, one of the asset files shows in browser “view source” as,

```plaintext
<link rel='preload' href='https://d5e4emqtwppd2.cloudfront.net/assets/locales/en-692973624e3f492c9c0634e89f74ffa930b18c27832c1c7d9ca16864c8da12ac.br.js' as='script'/>

```

But inside the container the files actually look like this:

```plaintext
# ls /var/www/discourse/public/assets/locales/en-692973624e3f492c9c0634e89f74ffa930b18c27832c1c7d9ca16864c8da12ac.*
/var/www/discourse/public/assets/locales/en-692973624e3f492c9c0634e89f74ffa930b18c27832c1c7d9ca16864c8da12ac.js
/var/www/discourse/public/assets/locales/en-692973624e3f492c9c0634e89f74ffa930b18c27832c1c7d9ca16864c8da12ac.js.br
/var/www/discourse/public/assets/locales/en-692973624e3f492c9c0634e89f74ffa930b18c27832c1c7d9ca16864c8da12ac.js.gz
/var/www/discourse/public/assets/locales/en-692973624e3f492c9c0634e89f74ffa930b18c27832c1c7d9ca16864c8da12ac.js.map

```

This happens when using AWS Cloudfront as the CDN provider. When CDN is disabled, it seems to work (at least for Chrome).

---

<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: [October 23, 2017, 12:37am UTC](https://meta.discourse.org/t/cdn-unable-to-access-assets-from-origin/72560/2 "2017-10-23T00:37:07Z")

</div>

I am not sure this is a bug. The “flipping” only happens in an AWS environment where you configure all s3 settings via ENV and then s3 acts as an origin for assets.

If you have s3 configured via env BE SURE to set DISCOURSE\_S3\_CDN\_URL and BE SURE to run `rake s3:upload_assets`, note this is a very advanced setup that I am working on now so it has to be all configured just-so.

---

<div class="post-metadata">

### Author: ![disc](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@disc](https://meta.discourse.org/u/disc)
#### Post date: [October 23, 2017, 4:21am UTC](https://meta.discourse.org/t/cdn-unable-to-access-assets-from-origin/72560/3 "2017-10-23T04:21:12Z")

</div>

Thanks for replying Sam.

Does `rake s3:upload_assets` only need to be run once, or does it need to be added to app.yml, so it runs every time `./launcher rebuild app` runs?

Also what happens if both DISCOURSE\_CDN\_URL and DISCOURSE\_S3\_CDN\_URL are configured via env? I’m not sure if the later will override the former, or if they serve different purposes.

---

<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: [October 23, 2017, 4:22am UTC](https://meta.discourse.org/t/cdn-unable-to-access-assets-from-origin/72560/4 "2017-10-23T04:22:22Z")

</div>

> [@disc](#):
>
> Does rake s3:upload\_assets only need to be run once, or does it need to be added to app.yml, so it runs every time ./launcher rebuild app runs?

It has to run every time after assets:precompile

> [@disc](#):
>
> Also what happens if both DISCOURSE\_CDN\_URL and DISCOURSE\_S3\_CDN\_URL are configured via env?

That is supported, just use different CDNs for both URLs, some paths have to hit the app still for the origin.

---

<div class="post-metadata">

### Author: ![disc](https://avatars.discourse-cdn.com/v4/letter/d/f6c823/32.png) [@disc](https://meta.discourse.org/u/disc)
#### Post date: [October 23, 2017, 5:18am UTC](https://meta.discourse.org/t/cdn-unable-to-access-assets-from-origin/72560/5 "2017-10-23T05:18:34Z")

</div>

Worked like a charm!

After adding a hook to run `rake s3:upload_assets` after assets:precompile, my DISCOURSE\_S3\_CDN\_URL works. So now I have two CDN urls backed by different origins. Nice, and thanks again!

---

<div class="post-metadata">

### Author: ![p\_shant\_gohel](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/p_shant_gohel/32/190604_2.png) [@p\_shant\_gohel](https://meta.discourse.org/u/p_shant_gohel)
#### Post date: [November 1, 2017, 5:42pm UTC](https://meta.discourse.org/t/cdn-unable-to-access-assets-from-origin/72560/6 "2017-11-01T17:42:25Z")

</div>

I am not able to see stylesheets in my s3 bucket after running the s3:upload\_assets task. I am able to see js files in s3 though.  
Is there a way to upload stylesheets to s3 too and use them from cdn.

---

<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: [November 1, 2017, 8:49pm UTC](https://meta.discourse.org/t/cdn-unable-to-access-assets-from-origin/72560/7 "2017-11-01T20:49:34Z")

</div>

> [@p\_shant\_gohel](#):
>
> Is there a way to upload stylesheets to s3 too and use them from cdn.

No, they have to originate from the web server, just run a second cdn for the web.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2024, 12:43pm UTC](https://meta.discourse.org/t/cdn-unable-to-access-assets-from-origin/72560/8 "2024-06-08T12:43:58Z")

</div>

This topic was automatically closed after 2421 days. New replies are no longer allowed.
