首页 > 解决方案 > 通过 apache Web 服务器 + tomcat 设置中的多个别名引用 tomcat URL

问题描述

我有一个 apache Web 服务器,它充当基本 url 的负载均衡器/网关,比如http://example.com

反过来,在 apache Web 服务器中存在路由逻辑,通过路径 http://example.com/app1、http://example.com/app2 将请求转发到各个 tomcat 服务器,例如app1 app2

在这里,app1 和 app2 是独立的 tomcat 实例,它们是独立的 webapp。

现在需要将http://example.com/app1也称为http://example.com/alias1,即 /app1 和 /alias1 都必须路由到 app1 对应的 tomcat 服务器,只有一个 app1已安装(即 alias1 不是单独的 tomcat 实例)

任何指向以这种方式为 tomcat webapp 设置别名的文档的指针都将不胜感激。

标签: apachetomcat

解决方案


您可以使用 apahce ReverseProxy 技术根据 url 将请求“路由”到不同的 tomcat:https ://httpd.apache.org/docs/current/mod/mod_proxy.html

你可以从这样的事情开始:

ProxyPass "/foo/" "http://foo.tamcat.lan:8080/foo/"
ProxyPassReverse "/foo/" "http://foo.tomcat.lan:8080/foo/"

ProxyPass "/bar/" "http://192.168.254.30:8080/"
ProxyPassReverse "/bar/" "http://192.168.254.30:8080/"

如果它正常工作,您可以为别名添加一个规则(可以是另一个 proxyPass、一个带有代理标志的 rewriteRule 或任何您需要/喜欢的)。

即使这不是最佳解决方案,如果您在同一个应用程序中有多个 tomcat servin,您也可以对流量进行负载平衡:https ://httpd.apache.org/docs/2.4/howto/reverse_proxy.html


推荐阅读