Apache ProxyPassReverse 重新映射域名但不重新映射端口

Apache ProxyPassReverse 重新映射域名但不重新映射端口

我正在尝试使用 Apache 代理作为我的基础架构中另一台服务器上运行的服务的前端。我们将它们称为 proxy.example.com 和 service.example.com。

Proxy.example.com 监听端口 80,而 service.example.com 监听端口 8888。当您连接到 service.example.com 时,它做的第一件事就是发送 302 重定向,其中包含端口 8888 - Apache 正确地重新映射了域名,但没有重新映射重定向中的端口。service.example.com 上的服务是第三方打包产品,因此我们假设我们无法以任何方式改变它的工作方式。

Apache 配置的相关部分如下所示:

ProxyPreserveHost On
ProxyPass / http://service.example.com:8888/
ProxyPassReverse / http://service.example.com:8888/

这里是一些(轻度匿名的)到端口 80 的 telnet。首先,直接进入 service.example.com:

$ telnet service.example.com 8888
Trying xxx.xxx.xxx.xxx...
Connected to service.example.com.
Escape character is '^]'.
GET / HTTP/1.0
Host: service.example.com

HTTP/1.0 302 Found
Date: Thu, 19 Jan 2012 10:38:54 GMT
Content-Type: text/html
Location: http://service.example.com:8888/directory/index.html

Connection closed by foreign host.

并通过 proxy.example.com 进行:

$ telnet proxy.example.com 80
Trying yyy.yyy.yyy.yyy... 
Connected to proxy.example.com.
Escape character is '^]'.
GET / HTTP/1.0
Host: proxy.example.com

HTTP/1.1 302 Found
Date: Thu, 19 Jan 2012 10:41:08 GMT
Location: http://proxy.example.com:8888/directory/index.html
Via: 1.0 service.example.com
Vary: Accept-Encoding
Content-Length: 0
Connection: close

Connection closed by foreign host.

那么,如何让 Apache 重新映射 302 重定向中的端口号以及域名?

答案1

我只是猜测,但据我所知,这里不需要 ProxyPreserveHost。我在非标准端口 (>9000) 上有后端服务,它仅使用 ProxyPass 和 ProxyPassRevere 指令即可按预期运行

注释掉 ProxyPreserveHost On 后你能再试一次吗?

相关内容