I've never used that feature, but http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_background_update claims to be a part of what you want.
@robryk @kuba yup. There's a bunch of hard earned knowledge in that config. That's to some extent the config that got a OCCRP through the Panama Papers traffic spike.
Another non-obvious thing: remember to cache your 404 and other errors. Otherwise your backend might be accidentally brought down by some random typo in a link somewhere.
@robryk @kuba
yup, that's what my Fasada nginx config does:
https://0xacab.org/rysiek/fasada/-/blob/master/services/etc/nginx/sites/example.com.conf?ref_type=heads#L38
This has been battle-tested in production as well. I should really write it up. 😉