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

前端 未结 5 1775
太阳男子
太阳男子 2020-12-07 11:19

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 noth

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 12:21

    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.

提交回复
热议问题