Ghost with custom CDN is possible?

I wonder if we can continue using Bunny CDN (A+ service for and ultra affordable price, I’m not doing promotion but I’m user from 3 years ago).

It’s all OK with Cloudflare but we think that we can avoid to keep centralized our data or management and save 19,50 bucks per month.

So, what’s the level of difficulty and what we need to link Bunny with Ghost? :slight_smile:

Thanks,
M.

I came across an article that may help point you in the right direction for getting setup:

3 Likes

Hey! Cool that you linked it, I’m still using that set-up although I would like to point out a couple downsides:

  • Not sure how well it works with Ghost Members.
  • It can break post previews in the editor (when you click to see the post rendered on the blog itself) Though it might be possible to set up an edge rule to avoid caching those as well.
  • Bunny aggressively tries to avoid updating their cache, which should be fairly obvious since it’s a CDN but still worth keeping in mind. When updating posts etc. you usually have to purge the relevant pages manually using their panel. It’s instant and not really difficult to do.

In any case, I’m still a happy customer of theirs and use it pretty extensively (outside of just having Ghost behind it). Also happy to answer questions if something is unclear :slight_smile:

2 Likes

Do you perhaps have any instructions on how you achieved this? Did you have any issues since>?

You can publish your site to subdomain.yoursite.com (and yoursite.com) so you can use subdomain.yoursite.com as origin on CDN cache server.

They will give you a new address that you can CNAME to cdn.yoursite.com.

So at the end you get yourdomain.com like always and cdn.yoursite.com cached (that pulls data from subdomain.yoursite.com).

Remember to add some rules to not caching member, admin and api routes. Google has more info if you look for ghost+cdn.

It’s a little tricky but it works and that’s what I’m doing at the moment.

You will need to edit your own configuration like Apache, Nginx or something.

I suggest to contact a server administrator if you don’t know what we are talking about (security is top important).

In Wordpress i usually offload images to store directly to bunnystorage for uploads and pull from bunny cdn for downloads. Trying to accomplish this with Ghost. Read the config documentation and came up with this to add in the config. But its not working. Can you tell whats wrong?

storage: {
active: ‘bunny’,
bunny: {
cdnUrl: ‘https://example.b-cdn.net’,
storageUrl: ‘https://storage.bunnycdn.com’,
accessKey: ‘your_access_key’,
storageZone: ‘your_storage_zone_name’
}
}

Ghost don’t support Bunny that way, you need to do some workaround or develop that variables on the code (offering a PR on main branch or forking your own instance).

Thanks. I see it supports S3 supported in this way so I was hoping bunny would be as well

I don’t think Ghost team will cover that because they have their own comercial agreements or just proximity with another parties (Fastly at this case).

If you want to use Bunny you need a server manager or manage it by yourself :slight_smile:

If Bunny is s3-compatible, I assume you would need to set the active storage adapter to whichever s3 storage adapter you’re using

It’s not S3 compatible

I integrated Bunny CDN by re-writing the image URL’s with nginx, it does does not break the backend /ghost - and Ghost can be edited on the non-cached origin URL. normal site URL

1 Like

I eventually got an adapter script written using the ghost docs. I’ve implemented it on a few sites and works well, I think that’s the best solution. Ghost uses a bunny storage zone to offload media, and uses a pull zone(CDN) to pull the images.

Agree, an adapter is the best solution, a minimum of hacking.
Is your adapter available for licencing / purchase? Feel free to DM.

1 Like

That’s a great idea. If I could recoup some cost of dev for it. Bunny is the best solution for offloading I’ve found. Costwise it’s pennies and you can add image optimisation on the pull zone and serve multiple sites at just $10. I use it with Wordpress clients as well for years, very good service. Can I get back to you on this?

Of course - would be very interesting!
My details in PM
/magnus

Just wanted to jump in here to update on this.

I have followed @skyeto’s blog post to set up BunnyCDN with a Ghost site and the actual caching worked out of the box. What didn’t work was accessing the /ghost route to edit the site and logging in to the portal as a member.

My assumption is that BunnyCDN has changed since June 2021/2022, so here’s what ended up working for me, in case anyone stumbles upon this thread in the future (just adding differences to the original post):

Edge Rules
To successfully bypass all API requests (relevant for the admin panel to work properly) you need to set “Cache Time” and “Browser Cache Time” to 0 for the following routes:

  • */ghost*
  • */members*

Caching settings that need adjustment
In the “General” caching settings:

  • “Query String Sort” needs to be off. This is necessary for the members login to the portal to work
  • “Strip Response Cookies” also needs to be off. Otherwise you won’t be able to log into the /ghost route, meaning you can’t edit your site.

Hope this helps :slight_smile:

Edit: just put the findings into a blog post to go into a bit more details:

3 Likes