【发布时间】:2021-05-23 09:26:32
【问题描述】:
我想做什么
我想运行 Apache httpd (2.4.x) 作为 Apache tomcat (9.0.x) 和 Elasticsearch 服务器的前端。
例如,用户应该看到
http://localhost/tomcat/
内部转发到
http://localhost:8080/
例如
http://localhost/tomcat/manager/status(外部由 httpd 服务)
检索自
http://localhost:8080/manager/status(内部来自Tomcat)
我做了什么
mod_proxy、mod_proxy_http、mod_rewrite 被激活。
在 httpd.conf 我添加了
ProxyPass /tomcat http://localhost:8080
ProxyPassReverse /tomcat http://localhost:8080
或者
<Location "/tomcat">
ProxyPass http://localhost:8080/
ProxyPassReverse http://localhost:8080/
</Location>
什么不工作
http://localhost/tomcat/ 正确地提供预期的页面。但是,该页面上的链接不会调整为新的基本 URL。
例如,页面包含
<a href="/docs/">Documentation</a>
单击该链接转到
应该去http://localhost/tomcat/docs
但指向http://localhost/docs
请注意,如果可能,我想在 Apache httpd 端使用解决方案(而不是重新配置 Tomcat),因为稍后我想对 Elasticsearch 后端使用相同的机制。
另一个小问题
省略尾部斜杠时
http://localhost/tomcat
转发适用于 HTML 页面本身,但对于嵌入式资源失败,例如,Tomcat 徽标应检索为
http://localhost/tomcat/tomcat.svg -> http://localhost:8080/tomcat.svg
而是指向
http://localhost/tomcat.svg 未翻译,因为它不再匹配位置模式。
【问题讨论】:
标签: apache tomcat mod-rewrite mod-proxy