我正在尝试使用指向后端 tomcat 应用程序的不同 URL 配置外部 Apache 前端。我以tomcat的manager app为例。
我希望用户像外部一样访问我的页面: 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 管理器 webapp 将其链接输出为“/manager”而不是“/tomcat-manager”,迫使我添加上面的 mod_rewrite 规则。理想情况下,我希望最终用户只看到该模式的浏览器 URL:
https://myhost.com/tomcat-manager/(whatever)
绝不是以下内容:
https://myhost.com/manager/(whatever)
在不修改底层 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代码也被重写了!
关于java - 在 tomcat html 输出中重写 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52827017/