[nginx] nginx - read custom header from upstream server

I am using nginx as a reverse proxy and trying to read a custom header from the response of an upstream server (Apache) without success. The Apache response is the following:

HTTP/1.0 200 OK
Date: Fri, 14 Sep 2012 20:18:29 GMT 
Server: Apache/2.2.17 (Ubuntu)
X-Powered-By: PHP/5.3.5-1ubuntu7.10
Connection: close
Content-Type: application/json; charset=UTF-8
My-custom-header: 1

I want to read the value from My-custom-header and use it in a if clause:

location / {
    // ...
    // get My-custom-header value here
    // ...
}

Is this possible? Thanks in advance.

This question is related to nginx reverse-proxy

The answer is


I was facing the same issue. I tried both $http_my_custom_header and $sent_http_my_custom_header but it did not work for me.

Although solved this issue by using $upstream_http_my_custom_header.


Use $http_MY_CUSTOM_HEADER

You can write some-thing like

set my_header $http_MY_CUSTOM_HEADER;
if($my_header != 'some-value') {
#do some thing;
}