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

Hi,

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!

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,78024,78024#msg-78024

Hello!

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

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

Hi Maxim,

Thanks very much for the reply!

nginx preserves only some specific headers (Set-Cookie and so on)
on X-Accel-Redirect.

I was wondering why it has to be this way? It makes life quite difficult
because I need some fine-grained control over the headers returned from
the backend to the client. I cannot really set all of them in
nginx.conf, because many are application-specific. Any idea? Again,
thanks very much! :slight_smile:

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,78024,78275#msg-78275

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs