apache - 通过 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 设置别名的文档的指针都将不胜感激。
解决方案
您可以使用 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
推荐阅读
- typescript - 如何使用字符串在打字稿中索引 json 对象
- java - 为什么不总是使用 RetentionPolicy.RUNTIME?
- apache-nifi - 使用 JsonTreeReader 在 ConsumeKafkaRecord 中设置 schema.name
- java - 将 android 通知分享到 whatsapp/电子邮件/其他 3rd 方应用程序
- python - 如何在信德/乌尔都语等其他语言中使用 Nlp Pos Tagging
- mysql - 为什么表数据没有传递到 MySQL 服务器
- c# - 数据库函数 Mock 在 c# web api 单元测试中不起作用
- java - 如何将 Array1[][] 中不存在于 Array2[][] 中的新行添加/追加到 Java 中的 Array2[][]?
- c# - 使用 .net 比较字符串在验证表单中是否有效
- design-patterns - 如果微服务架构中的数据量很大,我应该复制数据吗?