I would like to cache that response so that nginx hit the app server
from the first location which redirects to the 2nd location but that
returns a cached response.
When the redirect from the first location changes the second location
would have to cache it.
Is that possible? I’ve tried adding proxy_cache to the 2nd location,
like so:
But I’m not sure that asked exactly what I want to do.
It’s not. It’s about caching of a response with
an X-Accel-Redirect header, while your need to cache a response
after an internal redirect. What you need is expected to work
fine, see below.
This should work assuming you are using correct header to trigger
internal redirect, and the response returned doesn’t disable cache
(there is more than one way to do it, see Module ngx_http_proxy_module).