Welcome! Log In Create A New Profile

Advanced

FastCGI caching and X-Accel-Redirect responses

July 24, 2014 06:31AM
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.
Subject Author Posted

FastCGI caching and X-Accel-Redirect responses

gwilym July 24, 2014 06:31AM

Re: FastCGI caching and X-Accel-Redirect responses

Roman Arutyunyan July 24, 2014 09:30AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 123
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready