Apache - Tomcat ProxyPass VirtualHost - 上下文路径

发布于 2024-08-27 22:10:25 字数 697 浏览 8 评论 0原文

我在为 tomcat 中有两个不同上下文路径的两个应用程序配置 apache tomcat ProxyPass 指令时遇到问题。 tomcat 在 apache 后面运行,我使用 apache 来代理 tomcat 的请求路径。在 apache 中,我想通过主机名而不是上下文路径访问这两个应用程序。

场景:

tomcat 中的tomcat

https://domain:8443/app1
https://domain:8443/app2

应用程序在 apache 中具有上下文路径 app1 和 app2

我想启用这两个应用程序,如下所示:

https://app1.host/
https://app2.host/

在 apache 中,我为每个域创建了一个配置:

ProxyPass /  https://localhost:8443/app1
ProxyPassReverse / https://localhost:/8443/app1

奇怪的是 app1 只能通过 apache 使用上下文路径使用:

https://app1.host/app1

是否可以使用apache ProxyPass模块实现这样的设置?

谢谢你的帮助。

I have a problem configuring apache tomcat ProxyPass directive for two applications that have two different Context Paths in tomcat. The tomcat is running behind an apache and I use the apache to proxy path the requests to tomcat. In apache I want to access both application via a hostname instead of a context path.

Scenario:

tomcat

https://domain:8443/app1
https://domain:8443/app2

in tomcat the applications have the context path app1 and app2

in apache I want to enable both application as follow:

https://app1.host/
https://app2.host/

In apache I have created a configuration for each domain:

ProxyPass /  https://localhost:8443/app1
ProxyPassReverse / https://localhost:/8443/app1

The strange thing is app1 is only available through apache using the context path:

https://app1.host/app1

Is it possible to realize such a setup with apache ProxyPass module?

Thx for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇柔作态 2024-09-03 22:10:25

通过使用虚拟主机,您应该能够达到您想要的结果。另外,通过 AJP 协议而不是 HTTPS 将请求传递给 tomcat 也是一个好主意。尝试将其添加到 Apache 配置中,

NameVirtualHost *:443

<VirtualHost *:443>
    ServerName app1.host
    ProxyPass / ajp://localhost:8009/app1/
</VirtualHost>

<VirtualHost *:443>
    ServerName app2.host
    ProxyPass / ajp://localhost:8009/app2/
</VirtualHost>

如果您尚未更改 Tomcat 的默认服务器设置,那么这应该可以正常工作。否则,请确保指定在 Tomcat 的 conf/server.xml 文件中配置的 AJP 端口。应该有类似这样的一行:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

确保您在 Apache 配置中加载了 mod_proxy 和 mod_proxy_ajp 模块,这可能会根据您的 Apache 安装而有所不同。还要删除任何先前配置的“ProxyPass / ...”行,因为它们会干扰新配置。希望这对你有用。

You should be able to achieve the result you want by using virtual hosting. Also it's a good idea to pass the requests to tomcat via the AJP protocol instead of HTTPS. Try adding this to the Apache configuration

NameVirtualHost *:443

<VirtualHost *:443>
    ServerName app1.host
    ProxyPass / ajp://localhost:8009/app1/
</VirtualHost>

<VirtualHost *:443>
    ServerName app2.host
    ProxyPass / ajp://localhost:8009/app2/
</VirtualHost>

If you haven't changed the default server settings for Tomcat this should work just as it is. Otherwise make sure to specify the AJP port that is configured in Tomcat's conf/server.xml file. There should be a line similar to this:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Make sure that you have the mod_proxy and mod_proxy_ajp modules loaded in Apache configuration, this may vary depending on your Apache installation. Also remove any previously configured 'ProxyPass / ...' lines as they will interfere with the new configuration. Hope this works for you.

乖乖哒 2024-09-03 22:10:25

你可以尝试

ProxyPass /  https://localhost:8443/app1/
ProxyPassReverse / https://localhost:8443/app1/

最后的/

you can try

ProxyPass /  https://localhost:8443/app1/
ProxyPassReverse / https://localhost:8443/app1/

with the final /

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文