有没有办法删除 apache 反向代理请求标头?
当充当反向代理时,apache 添加 x-forwarded 标头,如此处所述。
http://httpd.apache.org/docs/2.2/ mod/mod_proxy.html#x-headers
在我的配置中,我已将服务器 A 配置为转发代理。有一条这样的规则:
RewriteRule proxy:(.*example.com)/(.*) $1.mysecondserver.com/$2 [P]
这条规则让服务器从我的其他服务器之一请求资源。
在第二台服务器(源)上,我有一个用于资源的虚拟主机容器和另一个重写规则,如下所示:
RewriteRule some-regex some-url [P]
它可能看起来没有意义,但还有很多其他事情发生,我遗漏了,因为它不是问题的一部分。
然而,最终的请求有这些标头:
[X-Forwarded-For] => ip of 1st server
[X-Forwarded-Host] => example.myseconserver.com
[X-Forwarded-Server] => example.com
我希望这些标头消失。
我似乎无法使用 mod_headers 取消设置它们。我可以向其中添加更多条目,但无法删除它们。
有什么想法吗?
When acting as a reverse proxy, apache adds x-forwarded headers as described here.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#x-headers
In my configuration I have configured server A as a forward proxy. There is a rule like this:
RewriteRule proxy:(.*example.com)/(.*) $1.mysecondserver.com/$2 [P]
This rule lets the server request the resource from one of my other servers.
On the second server (origin) I have a virtual host container for the resource and another rewrite rule like this:
RewriteRule some-regex some-url [P]
It may not seem to make sense like this but there is a lot of other stuff going on that I left out as it is not part of the problem.
However that final request has these headers:
[X-Forwarded-For] => ip of 1st server
[X-Forwarded-Host] => example.myseconserver.com
[X-Forwarded-Server] => example.com
I want those headers gone.
I seem to be unable to unset them with mod_headers. I can add more entries to them, but I can not remove them.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 Apache 2 开始,正如这个漂亮的答案所说,
理论上禁用它。根据我的经验,它没有任何效果。然而,与
和 结合起来,
它开始在某个地方发挥作用。
Since Apache 2, as this pretty answer says, the
theoretically disables it. In my experiences, it had no effect. However, combined with
and, with
somewhere it started to work.
更正的答案:没有办法做到这一点,因为它
在 mod_proxy_http.c 的源代码中进行了硬编码以修复此问题,搜索以下部分:
然后立即添加此代码:
然后通过运行 apxs2 -cia mod_proxy_http 进行编译。 c
corrected answer: there is no way to do that since its hardcoded
to fix this in the source code of mod_proxy_http.c search for the following part:
and immediately after that add this code:
then compile by running
apxs2 -cia mod_proxy_http.c
我在 CentOS 5 上的 httpd 2.2 上遇到了同样的问题。无法安装 httpd 2.4。但由于某些原因我无法完全切换到nginx。所以我通过在httpd和目标地址之间插入nginx代理来做到这一点。所以我有: httpd(
localhost:80/path
) -> nginx(localhost:81/path
) ->;http://your.destination/path
。安装步骤如下:在 nginx 中添加一个位置,该位置将删除这些 httpd 的反向代理请求标头。它可以看起来像这样:
I had the same problem on httpd 2.2 on CentOS 5. Installing httpd 2.4 wasn't possible. But because of some reasons I couldn't switch to nginx completly. So I did it by inserting nginx proxy between httpd and the destination address. So I had: httpd(
localhost:80/path
) -> nginx(localhost:81/path
) ->http://your.destination/path
. Installation steps are the following:Add an location in nginx that will remove those httpd's reverse proxy request headers. It can look like this: