I'm using Nginx proxy_cache to cache responses from a Node server. When that server is offline Nginx returns a custom 502 page. All going well so far...
When the Node server comes back online Nginx keeps returning the 502 page for 5 mins (my cache time). If I delete all the files in the cache dir it makes no difference. If I restart Nginx it busts the cache and starts serving real content again.
Is it normal for Nginx to cache 502s? Note that it's not caching a 502 response from the backend server it's caching the fact that the server isn't accessible.
What can I do to stop this?
I managed to figure this out myself. Nginx really does cache the knowledge that the upstream server is inaccessible.
To fix this I changed my cache config from
proxy_cache_valid any 5m;
toproxy_cache_valid 5m;
Removingany
implies you only want to cache 200, 301, and 302 responses.