使用proxy_pass时如何在nginx上添加响应头? [英] How to add a response header on nginx when using proxy_pass?

查看:1520
本文介绍了使用proxy_pass时如何在nginx上添加响应头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为从nginx后面的服务器收到的响应添加自定义标头。

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

虽然 add_header 适用于nginx处理的响应,当使用 proxy_pass 时,它什么都不做。

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

推荐答案

有一个名为 HttpHeadersMoreModule 的模块,可让您更好地控制标题。它不附带Nginx并需要额外安装。有了它,你可以这样做:

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.

这篇关于使用proxy_pass时如何在nginx上添加响应头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆