nginx with proxy_cache_use_stale not returning from cache when connection refused

Maxim Dounin mdounin at
Thu Dec 11 14:41:47 UTC 2014


On Wed, Dec 10, 2014 at 10:00:25PM -0500, new299 wrote:

> When the upstream goes away nginx gives the error "502 Bad Gateway
> nginx/1.4.6 (Ubuntu)". The log contains:
> " [error] 2624#0: *48941 connect() failed (111: Connection refused) while
> connecting to upstream,"
> Rather than serving it from cache as I would expect. It should be cached as
> the page was previous returned successfully.

The problem is in the "it should be cached" statement.

There are lots of cases when pages will not be cached even if 
returned - for example, because caching is explicitly disabled by 
response headers, or just not enabled and/or disabled with 
proxy_cache_min_uses, see Ruslan's answer.

So in your case the response is likely _not_ cached, and that's 
why "proxy_cache_use_stale" doesn't work for you.  To be sure 
you can follow Ruslan's suggestion to look into the cache 
directory, or use the $upstream_cache_status variable, see$upstream_cache_status.

Maxim Dounin

More information about the nginx mailing list