java - 在tomcat html输出中重写URL
问题描述
我正在尝试使用与后端 tomcat 应用程序不同的 URL 配置外部 Apache 前端。我以tomcat的管理器应用为例。
我希望用户像外部一样访问我的页面: https ://myhost.com/tomcat-manager
在内部,它被重定向到 http://localhost:8080/manager
我在 apache2 中使用 mod_proxy 和 mod_rewrite 尝试了以下配置:
RewriteEngine on
SSLProxyEngine on
RewriteRule "/manager/(.*)$" https://myhost.com/tomcat-manager/$1 [P]
ProxyPass /tomcat-manager http://localhost:8080/manager
ProxyPassReverse /tomcat-manager http://localhost:8080/manager
它主要工作,但我不喜欢 tomcat manager webapp 将其链接输出为“/manager”而不是“/tomcat-manager”,这迫使我添加上面的 mod_rewrite 规则。理想情况下,我希望最终用户只看到该模式的浏览器 URL:
https://myhost.com/tomcat-manager/(随便)
并且永远不会:
https://myhost.com/manager/(随便)
在不修改底层 webapp 的情况下配置 Apache 有什么建议吗?谢谢!
解决方案
我找到了我的问题的答案。它是 Apache 的 mod_proxy_html。我启用了相应的模块并修复了 Ubuntu 的 mod_proxy_html 缺失配置,如下所述:https ://serverfault.com/questions/684905/proxyhtmlurlmap-not-working-in-apache2-4
然后,我添加了以下配置代码:
ProxyHTMLEnable On
ProxyHTMLURLMap http://localhost:8080/manager/ /tomcat-manager/
ProxyHTMLURLMap /manager/ /tomcat-manager/
SetOutputFilter proxy-html
RequestHeader unset Accept-Encoding
就是这样。现在,我可以访问http://myhost.com/tomcat-manager并且其中的 html 代码也被重写了!
推荐阅读
- three.js - AFrame 指定 WebGL 版本
- node.js - 在 Node.js 的其他模块中通过引用使用数组是否绝对是这种情况?
- python - 如何在数组数组中巧妙地转换 Pandas Dataframe?
- javascript - 如何循环遍历 htmlcollection 对象?
- r - ggplot2中条形图条的不同颜色
- java - IntelliJ 中单元测试的 Java 9 模块问题:不能需要 JUnit Jupiter
- java - URI 类的 Java 检测:添加依赖项会引发 ClassNotFoundException
- postgresql - pgadmin 4.28 数据库还原未完成
- javascript - “requestOptions”未定义
- python - 如何通过深度学习预测未来价值?