FastCGI caching and X-Accel-Redirect responses

Roman Arutyunyan arut at nginx.com
Thu Jul 24 13:29:11 UTC 2014


On 24 Jul 2014, at 14:31, gwilym <nginx-forum at nginx.us> wrote:

> 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.

Backend responses with X-Accel-Redirect are not cached unless this header
is ignored.



More information about the nginx mailing list