How to configure Cloudfront CDN for /content/ folder?

I have a Docker/Kubernetes install of Ghost running on my home machine. I’ve also got a Cloudfront CDN domain that caches my website, which is dramatically faster. It seems really unnecessary to setup an S3 bucket with the storage adapter only to have the CDN slurp content from there, when I can get the benefits of ALL my content being cached. I did try the S3 adapter (two of them) and it’s incredibly fiddly to get set up properly.

I started coding up a storage adapter but the documentation is really thin, and I’m not really a strong JS developer. The simplest way would be to respond to requests to anything in the /content/* path with a redirect to get the same file from a different domain (but if a specific header is passed in, actually return it… that way I can let the CDN fetch files properly).

Is there a way to simply filter the outgoing HTML so based on the request headers, the URLs are different on the way out rather than handle a ton of redirects? Will I need to set up a CNAME subdomain to pretend the requests are from my domain? Will that even play nice with HTTPS?

Thanks,
JH

3 Likes