Want to understand s3_cdn_url files setting


(fearlessfrog) #1

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:

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:

http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html

…which then stops simple DNS Cloudflare (as in not even using Cloudfront) improvements, as we can’t have a 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.


S3 upload bucket, cdn url and bucket name in CNAME
(Jeff Atwood) #2

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


(fearlessfrog) #3

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.


(fearlessfrog) #4

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

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!


(Régis Hanol) #5

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 :wink:


(fearlessfrog) #6

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/upload.rb at master · discourse/discourse · GitHub


(Régis Hanol) #7

Here’s the fix :rocket:


Enable a CDN for your Discourse
S3 buckets containing periods not allowed
(Jeff Atwood) #8

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