Virtualbox +NAT Apache ProxyPass

Virtualbox +NAT Apache ProxyPass

请告诉我我做错了什么。我有一个配置,其中 apache 监听外部接口、托管域并充当几个内部服务器的代理。在大多数情况下,这工作得很好。当特定 URL 与 proxypass 指令匹配时,apache 会转发到内部站点。但是,我尝试使用 NAT 转发到另一个虚拟服务器,但它一直转发到主机,但仅从外部转发。例如,这是代理的配置:

<VirtualHost *:80>
   ServerName example.com

主机以名称 example.com 监听端口 12000。ProxyPass 将域的根转发到计算机,主机

ProxyPass / http://hostmachine:12000/

代理将 /billing 转发到主机上的端口 2080,然后使用 vbox NAT 从端口 2080 转发到端口 80,名称为 example.com/billing

ProxyPass /billing http://hostmachine:2080/billing/

我正在使用 NAT 将主机上的端口 2080 转发到虚拟服务器的端口 80。

vboxmanage showvminfo server1
...
NIC 1 Rule(0):   name = http, protocol = tcp, host ip = , host port = 2080, guest ip = , guest port = 80

这是问题,当我指导内部的(甚至代理服务器)浏览器到主机:2080,我从虚拟机中获取了预期的 html 文件服务器1。当我尝试从外部访问它时,通过代理路由,我从主机

从内部计算机:

telnet hostmachine 2080
Trying 10.28.45.100...
Connected to hostmachine.
Escape character is '^]'.
GET /billing/index.html
test billing server1
Connection closed by foreign host.

从外部浏览器:

http://example.com/billing
test billing hostmachine

从外表来看,这应该是这样的

example.com:80/billing -> ProxyPass -> hostmachine:2080 -> 2080:NAT:80 -> server1:80/billing

怎么了

example.com:80/billing -> ProxyPass -> hostmachine:80

答案1

发现问题出在代理服务器上。我忘记了 Apache 是按照事物出现的顺序来处理的,所以我需要将 /billing 放在 / 前面。例如,在域的 conf 文件中,

ProxyPass /billing http://hoststmachine:2080/billing/

然后

ProxyPass / http://hostmachine:12000/

相关内容