proxy_cache seems not working with X-Accel-Redirect
Maxim Dounin
mdounin at mdounin.ru
Wed Jan 11 17:42:32 UTC 2017
Hello!
On Wed, Jan 11, 2017 at 12:23:08PM -0500, bdesemb wrote:
> I want to add some clarification. My client calls is like "/app" and the
> server respond with a name. My file is stored at /var/local/data/<name>. I
> want to cache the response. So if I have another request on /app, Nginx
> should respond with the cached version of the file.
It is not clear what do you mean by "cached version of the file",
and what exactly do you want to cache.
Original question you are referring to was about caching responses
with the X-Accel-Redirect header. Files as referenced in these
X-Accel-Redirect responses are expected to exist permanently. The
question was how to cache responses with X-Accel-Redirect header
to avoid asking backend application each time, and return files
directly instead (using cached X-Accel-Redirect responses). I've
provided the configuration which does this.
If in your case files are generated by your app and then removed,
then this configuration will not work for you. Instead, you need
to cache full responses at the frontend level, and use an
additional backend nginx to resolve X-Accel-Redirect redirections.
That is, something like this:
server {
server 8080;
location / {
# here caching happens
proxy_pass http://127.0.0.1:8081;
proxy_cache foo;
}
}
server {
server 8081;
location / {
# here X-Accel-Redirect is processed
proxy_pass http://real-upstream-server;
}
location /path/to/files {
# a location to access files after X-Accel-Redirect
...
}
}
--
Maxim Dounin
http://nginx.org/
More information about the nginx
mailing list