Ghost admin and CDN caching

1 minute read

I recently switched from BIND to Unbound for my home network’s caching DNS server (which I should also write a post about), and in the process also simplified my local DNS to no longer have split-view versions of some of the domain names I own that have web sites hosted on my home network.

As a result my access to update this blog now goes through CloudFlare, just like everyone else, and as a result of that I had an issue with the Ghost admin interface being cached. Quick Googling didn’t return useful results, so documenting here to hopefully help someone else in future.

I noticed the issue when trying to revise a new post – I’d be able to create a new post, and anything I initially put in it would save, but after that first save it appeared nothing was being updated – I’d make changes, wait for it to auto-save, exit the editor, go back into the editor, and my changes were gone. Of course, it was being updated, but CloudFlare was caching the initial view of the editor page, so the updates were not showing up even on repeated reload of the page, clearing browser cache, etc.

To resolve this I updated the Nginx web server configuration to add the following.

        location /ghost {
            expires -1;
            add_header Cache-Control "private";
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto $scheme;

Specifically, the expires -1; and add_header Cache-Control "private"; lines ensure that CloudFlare will not cache anything under /ghost, the admin interface for Ghost. The proxy_ entries are the same as for the main / location.

I’ve tested and everything’s working as expected now!