Forward Custom Header from Nginx Reverse Proxy

Solution 1:

The proxy_set_header directive from the HttpProxyModule allows you to do this. For example:

proxy_pass http://apachehost;
proxy_set_header X-Custom-Referrer $proxy_add_<header_field_name_from_last_request>;

Solution 2:

By default the nginx forwards all the ( proxy_pass_request_headers on;) the header to the backend server. But if your request header ( may be custom header) includes underscore ( _ ) in the header name then nginx blocks those headers.

Ex: authenticate_type, cdn_enable.

To enable Nginx to pass all or the custom requested header to the backend turn on the underscore option on.

underscores_in_headers on;

Solution 3:

The module ngx_headers_more allows you to change and add http headers.

Solution 4:

You can use upstream headers (named starting with $http_) and additional custom headers. For example:

add_header X-Upstream-01 $http_x_upstream_01;
add_header X-Hdr-01  txt01;

next, go to console and make request with user's header:

curl -H "X-Upstream-01: HEADER1" -I http://localhost:11443/

the response contains X-Hdr-01, seted by server and X-Upstream-01, seted by client:

HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Mon, 30 Nov 2015 23:54:30 GMT
Content-Type: text/html;charset=UTF-8
Connection: keep-alive
X-Hdr-01: txt01
X-Upstream-01: HEADER1