Want to understand s3_cdn_url files setting

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.

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

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.

2 Likes

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!

2 Likes

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:

3 Likes

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… https://github.com/discourse/discourse/blob/master/app/models/upload.rb#L25

1 Like

Here’s the fix :rocket:

https://github.com/discourse/discourse/commit/f3905fd99ab2d26a98a9554f61be25c2922383ff

3 Likes

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