java - 在 tomcat html 输出中重写 URL

标签 java apache tomcat url-rewriting reverse-proxy

我正在尝试使用指向后端 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/

相关文章:

java - 未根据 Eclipse RCP 启动时的首选项设置代理

java - 为什么 Tomcat 的 LifyCycleSupport.java 使用数组而不是任何高级容器(ArrayList)来存储监听器?

java - Server Stop responding because of [Pool-Cleaner] :Tomcat Connection Pool but has failed to stop it. 这很可能造成内存泄漏

java - 如何使 Tomcat 中的日志轮换工作

java - Maven 配置不起作用

java - 由于我的 Recyclerview 中的属性 DescendantFocusability ="blocksDescendants",Edittext 无法编辑

Java 线程在不关注 OSX 时进入 hibernate 状态

java - 我必须配置哪些设置才能使用 XML 作为 Oracle 使用 Spring 存储过程的输入参数

php - 成功更改 apache 服务器的端口后,我的项目没有打开。我可以使用新端口号访问管理面板

带和不带 WWW 的 Apache 重定向 URL