brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: nginx fastcgi_cache plus X-Cache-Status shows whether PHP pages come from cache

Cache
~/tips/tip-cache-nginx-fastcgi-cache-status

fastcgi_cache WP;

Adds a response header that tells you if nginx answered from its FastCGI cache.

Without a status header it is guesswork whether a page was served from the cache or from PHP.

fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WP:10m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache WP;
fastcgi_cache_valid 200 10m;
add_header X-Cache-Status $upstream_cache_status;

The first two lines go in the http block, the rest in the location that passes to PHP-FPM. Without fastcgi_cache_valid nginx only caches responses where PHP sends Expires or Cache-Control, so you would see MISS forever. A response with Set-Cookie is never cached. Then curl -sI https://example.com/ | grep -i x-cache-status prints MISS on the first request and HIT on the next. Other values are BYPASS, EXPIRED, STALE, UPDATING and REVALIDATED. Add fastcgi_cache_bypass and fastcgi_no_cache conditions for logged-in users, or you will serve one visitor’s page to another.

Further reading: nginx: ngx_http_fastcgi_module

Going deeper: Guide: your Unraid cache is full and Docker stopped, how to find out why and fix it

More Cache tips fincore /var/lib/example/data.db npm cache verify fc-cache -f -v ~/.local/share/fonts proxy_cache app; Cache-Control: no-cache All Cache tips (24) All topics

Link