Web / NGINX Interview questions
What is caching in NGINX?
NGINX caching stores responses from an upstream server on disk or in memory so that repeated requests for the same content can be served without hitting the backend again.
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=1g; server { location / { proxy_cache my_cache; proxy_pass http://backend_app; proxy_cache_valid 200 10m; } }
Each cached entry is keyed by request attributes (URL by default) and expires based on proxy_cache_valid or headers from the backend. This significantly reduces load on application servers for content that doesn't change on every request, like product pages or API responses that update infrequently.
More Related questions...