# Want to understand s3\_cdn\_url files setting

**URL:** https://meta.discourse.org/t/want-to-understand-s3-cdn-url-files-setting/45799
**Category:** Support
**Created:** [17.Июнь.2016 01:18:55 UTC](https://meta.discourse.org/t/want-to-understand-s3-cdn-url-files-setting/45799 "2016-06-17T01:18:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![fearlessfrog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fearlessfrog/32/119653_2.png) [@fearlessfrog](https://meta.discourse.org/u/fearlessfrog)
#### Post date: [17.Июнь.2016 01:18:55 UTC](https://meta.discourse.org/t/want-to-understand-s3-cdn-url-files-setting/45799/1 "2016-06-17T01:18:55Z")

</div>

So we’re experimenting on using S3 for uploads. S3 is quite slow for, well anything really, so wanted to put a CDN like Cloudfront in-front of it. The setting :s3\_cdn\_url seems to be ideal for that. Using it is not quite what I expected though, so wanted help to check my understanding.

I can understand that it doesn’t change older posts without rebaking, but since enabling we see this on new posts:

 ![](https://global.discourse-cdn.com/meta/original/3X/2/7/27f4857b3f74c6d961ccb1e7e214f545affaca4b.png)

So, the actual optimized/thumb is shown in straight Slow S3, but the full inside the lightbox is Cloudfront? Is that right, as it would seem that CloudFront could be used in-front of S3 all the time for images?

I guess the other way to go would be to map a custom DNS entry to the S3 bucket and let something like Cloudflare alias it? Anyone have experience with this?

EDIT: Hmm, can’t use s3 virtual hosting domains with Discourse as it doesn’t like the periods in the bucket name then. It makes setting up like this not possible:

> **[Virtual hosting of general purpose buckets - Amazon Simple Storage Service](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html)**
>
> Use virtual hosting to serve multiple websites from a single web server.

..which then stops simple DNS Cloudflare (as in not even using Cloudfront) improvements, as we can’t have a [files.ourforum.com](http://files.ourforum.com) like mapping? Seems a bit of shame or maybe I am missing something?

EDIT2: Wildcard certs fault, ignore the edit bit if that helps.

---

<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: [17.Июнь.2016 03:05:27 UTC](https://meta.discourse.org/t/want-to-understand-s3-cdn-url-files-setting/45799/2 "2016-06-17T03:05:27Z")

</div>

Periods in s3 buckets do not work on https at all; please search for vast amounts of previous discussion on this.

---

<div class="post-metadata">

### Author: ![fearlessfrog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fearlessfrog/32/119653_2.png) [@fearlessfrog](https://meta.discourse.org/u/fearlessfrog)
#### Post date: [17.Июнь.2016 03:15:00 UTC](https://meta.discourse.org/t/want-to-understand-s3-cdn-url-files-setting/45799/3 "2016-06-17T03:15:00Z")

</div>

Yep, I understand how SSL wild card certificates and periods work (or don’t work), but my question was more why the discourse S3 CDN setting wasn’t being used for the baked optimize image as well as the click-through.

---

<div class="post-metadata">

### Author: ![fearlessfrog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fearlessfrog/32/119653_2.png) [@fearlessfrog](https://meta.discourse.org/u/fearlessfrog)
#### Post date: [22.Июнь.2016 21:37:34 UTC](https://meta.discourse.org/t/want-to-understand-s3-cdn-url-files-setting/45799/4 "2016-06-22T21:37:34Z")

</div>

So if my understanding is correct then I think there might be a bug here:

> <https://github.com/discourse/discourse/blob/ebd4b4577168644ff1132af85215bfa2034ecdbb/lib/cooked_post_processor.rb#L244>

When an image has a lightbox built when cooking a post, it seems that the non CDN URL is used, since when an image is ok to display without lightbox then the CDN _is_ used. If anything it would be better the other way around, as in the multiple images in posts in the main topic is exactly the thing that would benefit from the CDN.

If my understanding of the feature is correct then I can try to figure out a pull request fix, but if it’s not then I need someone on the Discourse team like @codinghorror to take a look and let me know where I misunderstand the intention of this bit. Cheers!

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [22.Июнь.2016 21:51:31 UTC](https://meta.discourse.org/t/want-to-understand-s3-cdn-url-files-setting/45799/5 "2016-06-22T21:51:31Z")

</div>

There’s definitely a bug and I think you’re on the right track. I’ll have a look at it tomorrow morning unless you manage to do a PR before that 😉

---

<div class="post-metadata">

### Author: ![fearlessfrog](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fearlessfrog/32/119653_2.png) [@fearlessfrog](https://meta.discourse.org/u/fearlessfrog)
#### Post date: [22.Июнь.2016 21:57:34 UTC](https://meta.discourse.org/t/want-to-understand-s3-cdn-url-files-setting/45799/6 "2016-06-22T21:57:34Z")

</div>

Thanks. I need to set up my local discourse dev env this weekend, as I’d like to help out more and contribute back.

Just by eyeballing it on github, my best guess is that the thumbnail returned URL needs to respect the relative path for the CDN, so it should be a small tweak around here.. [discourse/app/models/upload.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/app/models/upload.rb#L25)

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [27.Июнь.2016 20:10:11 UTC](https://meta.discourse.org/t/want-to-understand-s3-cdn-url-files-setting/45799/7 "2016-06-27T20:10:11Z")

</div>

Here’s the fix 🚀

[https://github.com/discourse/discourse/commit/f3905fd99ab2d26a98a9554f61be25c2922383ff](https://github.com/discourse/discourse/commit/f3905fd99ab2d26a98a9554f61be25c2922383ff)

---

<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: [30.Июнь.2016 20:59:18 UTC](https://meta.discourse.org/t/want-to-understand-s3-cdn-url-files-setting/45799/8 "2016-06-30T20:59:18Z")

</div>

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