0

We have a downstream application which is setting some custom headers to the requests from browser before hitting nginx. nginx serves only static contents. ie browser >> application A >> nginx

The requirement is that the nginx should be able to return all the headers which it receives as is to the downstream server which would give it back to the browser. by default its returning only the generic headers ( cookies etc, expiry etc ) and not retuning the custom ones sent by the downstream server.

For instance, there is a header with name appnumber which nginx receives with value app01. I tried to explicitly set it with the following rule to set it manually if it exist, but did not help as it throws error that variables are not allowed.

if ($appnumber) {
    add_header appnumber $appnumber;
}

Can someone please guide me here?

Anjca
  • 1
  • 1
  • 1

1 Answers1

0

The request headers are stored under $http_ variable. You could try something like

if ($appnumber) {
   add_header appnumber $http_appnumber;
}

Refer http://nginx.org/en/docs/http/ngx_http_core_module.html and nginx - read custom header from upstream server

David
  • 887
  • 8
  • 7
  • 1
    Thanks for the suggestion David, but the 'add_header' does not accept any variable dynamically as per its format - nginx config would fail. – Anjca Oct 18 '17 at 19:41