Pass headers from FastCGI backend to client while X-Accel-Redirect

Maxim Dounin mdounin at mdounin.ru
Fri Apr 23 00:48:34 MSD 2010


Hello!

On Thu, Apr 22, 2010 at 09:56:29AM -0400, riobard wrote:

> I'm having some trouble with FastCGI backend sending custom 
> headers to client while using X-Accel-Redirect. My backend PHP 
> does something like this: 
> 
> 
> header( "custom-header: some-value" );
> header( "X-Accel-Redirect: " . $cache_file);
> 
> 
> If I don't use X-Accel-Redirect everything is fine (i.e. I can 
> see the custom-header from client side). But Nginx seems to 
> strip all headers set by my PHP backend if X-Accel-Redirect is 
> used. Any idea why and how I can add it back? Thanks very much!

nginx preserves only some specific headers (Set-Cookie and so on) 
on X-Accel-Redirect.  For anything else you may to do something 
like this:


    location / {
        fastcgi_pass ...

        # here are headers returned:
        # X-Accel-Redirect: /redirected/...
        # X-Custom: something
    }

    location /redirected/ {
        internal;
        add_header X-Custom $upstream_x_custom;
        ...
    }

Note that if "/redirected/" does proxy_pass/fastcgi_pass in it's 
turn you have to store $upstream_x_custom into some intermediate 
value via "set" directive (or it will be cleared/overriden by next 
upstream request).

Maxim Dounin



More information about the nginx mailing list