Nginx cache to serve cached content instead of error pages

Adrian Ber asked:

Is there any way to configure Nginx to serve cached content instead of error pages?

Let’s suppose that accessing a page /abc.html resulted in 200 and the page was cached. Meantime something changed (the file was deleted or, if nginx is used as a reverse proxy there is a 50x server error etc) and instead of serving the error, I would like to serve the last “good” cached page.

My answer:


nginx is fully capable of caching proxied (or fastcgi) content. In this case you will want to adjust your proxy_cache_use_stale directive (or fastcgi_cache_use_stale) to reflect the circumstances in which you want to serve cached data.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.