Nginx proxy caching can absorb traffic spikes by serving responses from disk without hitting your backend. Configure cache zones, TTLs, and bypass conditions with our generator.
Declare the zone in http, then enable it per location with a TTL per status code.
proxy_cache_path /var/cache/nginx keys_zone=app:10m max_size=1g inactive=60m;
location / {
proxy_cache app;
proxy_cache_valid 200 10m;
proxy_cache_use_stale error timeout updating;
add_header X-Cache-Status $upstream_cache_status;
}Skip the cache for requests with cookies or authorization headers using proxy_cache_bypass and proxy_no_cache, or you can serve one user’s page to another.
Open the Static site generator
Expose $upstream_cache_status as a response header and look for HIT, MISS or EXPIRED.
Same mechanism; proxy_cache stores upstream HTTP responses, fastcgi_cache stores PHP-FPM responses.