Proxy_cache seems not working with X-Accel-Redirect

My config

location ~ /cached/ {
proxy_pass http://apache;
proxy_cache cache;
proxy_cache_valid 2h;
proxy_cache_key “$host|$request_uri”;


location /htdocs_internal/ {

        alias $htdocs_path;


Requests with header in reply X-Accel-Redirect not cached, every time
request is sent to apache. When i add these directives
proxy_pass_header X-Accel-Redirect;
proxy_ignore_headers X-Accel-Redirect;
cache works fine (but is useless :slight_smile: ), so it isn’t problem with “no
headers from apache.

Posted at Nginx Forum:


On Fri, Aug 09, 2013 at 06:20:21AM -0400, gray wrote:

location /htdocs_internal/ {
headers from apache.
Yes, proxy_cache can’t cache responses with X-Accel-Redirect.

As a workaround, you may use an additional proxy layer with
proxy_cache and proxy_ignore_headers X-Accel-Redirect +
proxy_pass_headers X-Accel-Redirect.

Maxim D.