Caching Configuration in Nginx
From the Nginx cheat sheet ยท Caching & Performance ยท verified Jul 2026
Caching Configuration
Setting up various caching strategies
nginx
# Browser caching for static files
location ~* \.(jpg|jpeg|png|css|js)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
# Proxy cache
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=1g;
server {
location / {
proxy_cache my_cache;
proxy_cache_valid 200 1h;
proxy_pass http://backend;
}
}๐พ Multiple cache zones for different content
โก Microcaching for dynamic content
๐ stale-while-revalidate for better UX
๐ X-Cache-Status header for debugging