有什么方法可以使用 HTTP 代理将 Apache 连接到 Tomcat,以便 Tomcat 获得正确的传入主机名而不是 localhost?我在 apache 中使用这个指令:
ProxyPass /path http://localhost:8080/path
但它以本地主机的形式出现,当我们在同一台服务器上有一堆网站时,这是无用的。我可以在服务器配置中手动设置主机:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
proxyName="pretend.host" proxyPort="80" />
但是,这又不能服务于多个站点。而且我不喜欢为每个站点使用不同的内部端口的想法,这听起来真的很难看。
代理的时候是不是不能转移端口?
(如果你问我为什么不直接使用 AJP,答案是 this error。在放弃 Tomcat and Apache entirely 之前,我正在尽我所能)
最佳答案
您正在寻找的设置是:
<VirtualHost *:80>
ServerName public.server.name
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
请注意,我们使用 localhost 作为代理目标。我们可以这样做,因为我们启用了 ProxyPreserveHost .文档指出
It is mostly useful in special configurations like proxied mass name-based virtual hosting, where the original Host header needs to be evaluated by the backend server.
这听起来和你正在做的一模一样。
关于 Apache + 汤姆猫 : Using mod_proxy instead of AJP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/956361/