A stale cache contains content whose configured freshness lifetime has expired. Nginx can still serve that content when the upstream application fails, times out, returns invalid headers, or produces selected HTTP errors. section 20.3
Different lifetimes for web pages and API responses
Configure web responses to remain cached for six hours and permit stale delivery during upstream failures. Configure API responses to expire after one minute without stale delivery; after the API container stops, Nginx returns HTTP 502. section 20.3
Listing 20.3 Nginx as a caching reverse proxy for HTTP content
...
location = /api/image {
proxy_pass http:/./iotd/image;
proxy_set_header Host $host;
proxy_cache SHORT;
proxy_cache_valid 200 1m;
...
}
location / {
proxy_pass http:/./image-gallery;
proxy_set_header Host $host;
proxy_cache LONG;
proxy_cache_valid 200 6h;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
...
}
Inspect the Nginx locations that define cache lifetimes and the errors allowed to trigger stale responses. section 20.3
