java重写tomcat html输出中的URL
我正在尝试配置一个外部Apache前端,该前端与后端tomcat应用程序的URL不同。我以tomcat的manager应用程序为例
我希望用户能够像以下那样访问我的页面: 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_重写规则。理想情况下,我希望最终用户只看到模式的浏览器URL:
https://myhost.com/tomcat-manager/(whatever)
永远不要做以下事情:
https://myhost.com/manager/(whatever)
有没有建议在不修改底层webapp的情况下配置Apache?谢谢
# 1 楼答案
我找到了问题的答案。它是Apache的mod_proxy_html。我启用了相应的模块,并修复了Ubuntu的mod_proxy_html缺失配置,如下所述:https://serverfault.com/questions/684905/proxyhtmlurlmap-not-working-in-apache2-4
然后,我添加了以下配置代码:
就这样。现在,我可以访问http://myhost.com/tomcat-manager,其中的html代码也被重写了