FastCGI caching and X-Accel-Redirect responses
gwilym
nginx-forum at nginx.us
Thu Jul 24 10:31:52 UTC 2014
I have Nginx sitting in front of a php5-fpm pool via fastcgi. The
application will serve static assets by means of responding with an
X-Accel-Redirect to an internal location.
My intention is to avoid repeatedly hitting the app for a particular URL for
short periods of time to cover bursts of traffic.
My (incomplete) cache settings are like so, as an example of things I have
tried:
fastcgi_cache FASTCGI_ASSETS;
fastcgi_cache_key $request_method$scheme$host$request_uri;
fastcgi_cache_use_stale off;
fastcgi_cache_valid any 10s;
fastcgi_cache_methods GET HEAD;
fastcgi_ignore_headers Expires Cache-Control Set-Cookie;
I have a feeling that there is some special case when X-Accel-Redirect is
present in the response which causes it to not be cached. I cannot ignore
the field because I need to use it to service the redirect within the app
server, but if I hit "/foo" resulting in the app responding with an
accel-redirect, I would like "/foo" to not hit the app again for a certain
period.
As it stands no combination of fcgi cache settings seem to work for me. I
can get non- accel-redirect responses cached OK otherwise. Any request with
X-Accel-Redirect in the header appears as http cacheable 0 in the debug
log.
I know I can achieve this by putting a second caching server in front of the
app server but it would save me a lot of hassle if the above were possible.
Some of the assets themselves could also be large so attempting to cache the
content could be too much, so caching the redirect (freeing up the time cost
of the app producing it) would be a win for me.
This is Nginx 1.6.0 on debian squeeze (dotdeb build).
Thankyou.
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,252018,252018#msg-252018
More information about the nginx
mailing list