Full Page Caching with Bunny CDN: Make you fast Ghost blog faster

Just wanted to share that we can easily do full page caching in Bunny CDN with ghost blogs.
I previously wrote about Increasing speed of ghost blog with cloudflare workers. But this bunny cdn method is much much easier.
Full page Caching dramatically reduce time to first byte, making you already fast self hosted ghost blog much faster. And also reduce load on your origin server. So you can serve large traffic with relatively cheap hosting.
You can do full page caching for logged out users. Member features works normally.
Has no problem with AdSense and even ezoic codes.
If you don’t want full page caching you can just do reverse proxy caching only static files.

No nginx modification needed.

Surprising discovery Bunny has much better routing than Cloudflare.

And the whole post is here:

5 Likes

Helpful article, thanks.

It could be improved by mentioning how to setup cached purging-- how to notify Bunny when Ghost content is updated or deleted.

That’s especially important if perma-caching is used, so the CDN will always assume that it’s cache is fresh:

Why use a perma-cache? For self-hosters, especially those hosting at home, this could smooth over downtime due to power outages or maintenance.

1 Like

Glad you liked it, I had actually created an automated way to purge cache. But posted on reddit Reddit - Dive into anything
Here is the reddit link to do that.
I didn’t updated the blog because I am working on techweirdo.net. and I will eventually merge those two.
Btw, at tech weirdo I am using ghost with bunny, but a side note, if you have login, members etc perma cache won’t work.
In My case, I am using 2 distributions. the techweirdo.net which only serves the html is served through the origin shield cache, as it does that dynamic full page caching based on cookies. And I serve all the static assets like images, css , js through cdn.techweirdo.net which uses perma cache. And I do the url rewrite using nginx subfilters. When something changes like, posts etc. You don’t need to purge the static assets. Only create the automation to purge the html distribution.
I know I made it complex, but it is kinda the best of both worlds.
Also I did a load testing on the site, it managed 17000 synthetic page view in 3 minutes (load testing servers got overloaded).

2 Likes


And this is my absolutely unnecessarily overcomplex ghost blog setup :smiling_face_with_tear:

2 Likes

It makes sense to me.

1 Like

Hey @smartgoat, thanks for sharing the article.

I tried it but email signup has stopped working with the smart cache off + edge rules approach.

I tried with smart cache + no edge rules and that worked. Members can sign up now.

But there is a problem: I’m getting cache-status “MISS” for all the pages on the site, for both signed-in and signed-out users. Only assets are showing “HIT”

Due to that, even global TTFB checkers show high TTFB and “MISS” for cache status in all locations.

Can you please assist me with what I might have done wrong?

Thanks :)

“smart cache” only cache assets (it won’t cache HTML).

below is config which works well for me

  1. Cache Expiration Time = 3days (or anything higher you want)
  2. Vary Cache → Cookie Value = ghost-members-ssr
  3. “Strip Response Cookies” = Turn off
  4. Override Cache Time = 0
    Url match = /ghost/api, /members ,*/sitemap.xml, */robots.txt

Also please note,
with this approch we have to take care of the “Pullzone purging” when we modify the site (for example theme change).

for this, I created a simple cloudflare worker which purges the pullzone whenever “site.changed” webhook fires.

1 Like

Have you turned off strip response cookie? That may cause the problem. I have followed the exact setup I explained here at techweirdo.net and it works. If it is still not working, please share screenshots of all your settings. @prathap_puthran you don’t necessarily need to bypass/ghost/ and /members/ if you also add ghost-admin-api-session cookie.
Also you can find the cloudflare workers script for cache purging @prathap_puthran suggested here.
Modify it for bunny cdn like this

async function handleRequest(request) {
const { pathname } = new URL(request.url);

// Check if the request is to trigger full cache purge
if (pathname === '/purge-full-cache) {
// Purge the entire cache in Bunny CDN
const purgeResponse = await fetch('https://api.bunny.net/pullzone/YOUR_PULL_ZONE_ID/purgeCache', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'AccessKey': 'BUNNY_ACCESS_KEY'
}
});

Please let me know.

1 Like

Here are my two setups as per your blog post @smartgoat:

Setup #1

:no_entry: Edge rule is disabled in this case

Setup #2

:no_entry: Smart cache is disabled in this case, rest is same.

PS: For some reason, the new Bunny dashboard shows “Response Header” as greyed out in the drop-down. I had to switch to the old dashboard to add that condition.

Problems With Each Case

Setup #1

In this setup with smart cache ON + edge rule OFF, everything works normally. Members sign-in, sign-up everything works fine.

Only static assets show cache-status as HIT. Posts and pages show MISS

Setup #2

In this setup with smart cache OFF + edge rule ON, everything shows cache-status as HIT. Even member sign-up works fine, it’s the member sign-in that’s broken. If a member tries to sign in, Ghost successfully sends the magic link, and clicking it shows a notification that shows logged in. But when the “Account” button is clicked, it again asks for sign-in.

I noticed the same on techweirdo.net as well. That will be a problem for users to switch between the membership plans or change their profile details.

1 Like

Okay, I found the issue.

The browser caching was on in my case at techweirdo, and probably same for you too.

In the caching page, set browser cache to do not cache, then clear cache for your site, and try now. It should solve the issue.

Thanks for pointing that out. I completely missed that.

Thanks @smartgoat for sharing the quick fix. That worked like a charm. Now my site is loading with blazing fast speed :fire:

One small request, please write an article about the ideal Bunny CDN settings for Ghost, just like you did for Cloudflare :)

1 Like

Well, there is nothing extra other than this setup at bunny. There are a lot of settings at cloudflare, but bunny usually does most of the things out of the box. You don’t need extra settings. Although you can squeeze a little more out of bunny, but to do that you need to self host ghost on a vps (require nginx vhost modification). If you can do that, then you can offload all static assets to a cdn subdomain and load those static assets from bunny perma cache. I do that at techweirdo. But may be overkill.

1 Like

I’m self-hosting so no harm in giving it a try ;)

Thanks again

I want to add one update. Perma cache works now. I have also updated my post accordingly.

hi you’re instructions are great… for sure i’m off topic but ask you if can help me… i have wordpress and woocommerce site and already made cache at the edge with bunny using as proxy… but cannot use permacache… do you know if i can use permacache only for static file like media? probably not js or css do you know how or can guide me? i know you use ghost i’m only asking for a logical help if the platform could be similar many thanks greetings fro italy

Yes @Nicola_Rossi you probably can do that too. Use the bunny cdn plugin for WordPress and create a seperate cdn.yourdomain.com distribution for you site. That should work. :smiling_face_with_tear:

Thank you :upside_down_face:.

hi probably with the old bunny plugin was simplier… now it makes the wizard and not so simple i try to ask to bunny support…
i’ve created cdn.mydomain on cloudflare and points to a bunny zone created…
that bunny zone attached to the permacache storage ones…
but when i try to configure the plugin bunny on WP i not know how to setup
it creates another pull zone with the main domain
and not know how to setup the cdn pull zone and storage zone already created

@Nicola_Rossi I actually created one with the new plugin long time ago. I quit don’t remember the process. But try setting up your cdn first via bunny dashboard then with the plugin set that as your cdn. Sorry for the image quality.


probably i do wrong i make same cdn setup as main pointing to the zone on bunny as for my proxy at the edges setup…
probably i have to create cdn as a sort of alias on my plesk config then create cdn A (cf) field pointing to my plesk server then using it on the pull zone…like you first image (ip address )
i completely lost the way sorry…
someone said that not possible to use permacache with cache at the edges probably is possible as you using only for static files like image (not know if also js and css) pushing on permacache zone… and using in correct way the WP bunny plugin to serve only static from that zone+permacache

Previously it was not possible to use permacacche. And that blog post is probably an old one. Now you can use permacache as there is a new edge rule added to bunny cdn about purging permacache. Which I am actually using for ghost too.