阿帕奇+ Tomcat:使用 mod_proxy 代替 AJP
有什么方法可以使用 HTTP 代理将 Apache 连接到 Tomcat,以便 Tomcat 获取正确的传入主机名而不是 localhost? 我在 apache 中使用这个指令:
ProxyPass /path http://localhost:8080/path
但它是作为 localhost 来的,当我们在同一服务器上有一堆站点时,这是没有用的。 我可以在服务器配置中手动设置主机:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
proxyName="pretend.host" proxyPort="80" />
但这又不能为多个站点提供服务。 我不喜欢为每个站点使用不同的内部端口的想法,这听起来真的很难看。
代理的时候没有办法转移端口吗?
(如果你问我为什么不只使用 AJP,答案是 这个错误,在完全放弃 Tomcat 和 Apache 之前,我正在尽一切努力。
Is there any way I connect Apache to Tomcat using an HTTP proxy such that Tomcat gets the correct incoming host name rather than localhost? I'm using this directive in apache:
ProxyPass /path http://localhost:8080/path
But it comes through as localhost, which is useless when we have a bunch of sites on the same server. I could set the host manually in the server config:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
proxyName="pretend.host" proxyPort="80" />
But that again doesn't serve more than one site. And I don't like the idea of using a different internal port for each site, that sounds really ugly.
Is there no way to transfer the port when I proxy it?
(If you ask why I don't just use AJP, the answer is this error. I'm trying everything I can before giving up on Tomcat and Apache entirely)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您要查找的设置是:
请注意,我们使用 localhost 作为代理目标。 我们可以这样做,因为我们启用了 ProxyPreserveHost。 该文档指出
这听起来和你正在做的一模一样。
The settings you are looking for are:
Note that we're using localhost as the proxy target. We can do this since we enable ProxyPreserveHost. The documentation states that
which sounds exactly like what you are doing.
我认为,如果您希望同一服务器上有多个站点,最好的选择是在 Apache 配置中使用虚拟主机。 这是一个例子:
只要您在外部 DNS 中注册了 server.domain.com,传入的主机名就会显示在客户端 URL 中。 我使用此方法运行托管 6 个独立站点的单个服务器,其中 3 个站点由 Tomcat 支持。
I think your best bet if you want multiple sites on the same server is to use virtual hosts in your Apache configuration. Here's an example:
As long as you have server.domain.com registered in your external DNS, the incoming host name will be displayed in client URLs. I'm running a single server hosting 6 separate sites, including 3 that are back by Tomcat, using this method.
您仍然可以使用 AJP,而且您应该使用 AJP,因为它比 HTTP 更快。 只需确保在 http.conf 中启用它:
在这种情况下,此配置对我有用:
You can still use AJP, and you should since it's faster than HTTP. Just make sure to enable it in http.conf:
In that case, this configuration works for me: