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

**URL:** <https://www.ruby-forum.com/t/pass-headers-from-fastcgi-backend-to-client-while-x-accel-redirect/187398>\
**Category:** NGINX\
**Created:** [April 22, 2010, 3:57pm UTC](https://www.ruby-forum.com/t/pass-headers-from-fastcgi-backend-to-client-while-x-accel-redirect/187398 "2010-04-22T15:57:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![riobard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@riobard](https://www.ruby-forum.com/u/riobard)\
**Post date:** [April 22, 2010, 3:57pm UTC](https://www.ruby-forum.com/t/pass-headers-from-fastcgi-backend-to-client-while-x-accel-redirect/187398/1 "2010-04-22T15:57:27Z")

</div>

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:

> **[Pass headers from FastCGI backend to client while X-Accel-Redirect](https://forum.nginx.org/read.php?2,78024,78024#msg-78024)**
>
> 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: \[code\] header( "custom-header: some-value" ); header( "X-Accel-Redirect: " .

---

<div class="post-metadata">

**Author:** ![riobard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@riobard](https://www.ruby-forum.com/u/riobard)\
**Post date:** [April 22, 2010, 10:49pm UTC](https://www.ruby-forum.com/t/pass-headers-from-fastcgi-backend-to-client-while-x-accel-redirect/187398/2 "2010-04-22T22:49:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![riobard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@riobard](https://www.ruby-forum.com/u/riobard)\
**Post date:** [April 23, 2010, 2:29am UTC](https://www.ruby-forum.com/t/pass-headers-from-fastcgi-backend-to-client-while-x-accel-redirect/187398/3 "2010-04-23T02:29:49Z")

</div>

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! 🙂

Posted at Nginx Forum:

> **[Re: Pass headers from FastCGI backend to client while X-Accel-Redirect](https://forum.nginx.org/read.php?2,78024,78275#msg-78275)**
>
> 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: \[code\] header( "custom-header: some-value" ); header( "X-Accel-Redirect: " .
