Caching not working correctly - fastcgi-cache header set to STALE

I have ran into an issue where using fastcgi_cache_use_stale with fastcgi_cache_background_update can cause issues with 404 pages. If you ever delete a page that has been cached, nginx will keep serving the cached page even if your origin server responds with 404.

It’s because WordPress adds Cache-Control: no-cache, must-revalidate, max-age=0 and expires: Wed, 11 Jan 1984 05:00:00 GMT to 404 pages which nginx will refuse to cache.

That’s why you should use any value in fastcgi_cache_valid and always use fastcgi_ignore_headers Cache-Control Expires . This way your deleted pages will properly return 404 error code. I have updated the code samples to reflect this.

Never MISS the cache with Nginx microcaching – siipo.la

What is your fastcgi_cache_valid?

My guess is:
Nginx refuses to update the cache because private pages have Cache-Control: no-cache header. Thus, the old caches (the published version) are used.

1 Like