How do you configure nginx microcaching for dynamic content?
IntermediateProductionLoad Balancing, Proxies & nginx in Production
Answer
proxy_cache_path /var/cache/nginx keys_zone=micro:10m max_size=1g inactive=10m;
location / {
proxy_cache micro;
proxy_cache_valid 200 1s;
proxy_cache_lock on;
proxy_cache_use_stale updating;
add_header X-Cache $upstream_cache_status;
proxy_pass http://app;
}
A 1-second cache turns a thousand requests per second for the same URL into one backend hit, only for content safe to share across users.
More on Load Balancing, Proxies & nginx in Production
How do you choose between ALB, NLB and an nginx or Envoy fleet?IntermediateHow do you tune ALB idle timeout and backend keep-alive to avoid 502s?IntermediateWhich nginx directives matter most for a production reverse proxy?IntermediateHow do you do rate limiting and abuse protection in nginx?IntermediateHow do you achieve zero-downtime configuration reloads in nginx and HAProxy?IntermediateHow would you design a highly available load-balancing tier on-prem or in a colo?Advanced