Search code examples
nginxhttp-headersproxypass

How to add a response header on nginx when using proxy_pass?


I want to add a custom header for the response received from the server behind nginx.

While add_header works for nginx-processed responses, it does nothing when the proxy_pass is used.


Solution

  • There is a module called HttpHeadersMoreModule that gives you more control over headers. It does not come with Nginx and requires additional installation. With it, you can do something like this:

    location ... {
      more_set_headers "Server: my_server";
    }
    

    That will "set the Server output header to the custom value for any status code and any content type". It will replace headers that are already set or add them if unset.