Tomcat 提供 mod_proxy 和 apache 的 URL 错误

发布于 2024-08-18 10:42:31 字数 1068 浏览 7 评论 0 原文

我已经使用 apache 设置了一个主机来提供静态页面,并使用 Tomcat 来提供我的 Web 应用程序(请参阅此问题)。静态页面是来自

http://myhost.com

的服务器,动态(tomcat)页面是来自

http://myhost.com/myapp"

mod_proxy 确保“http://myhost.com/myapp" 被转发到运行在“http://myhost.com:8080”。

问题是,现在您在“http://myhost.com/myapp”上获得标准 Tomcat 介绍页面但如果您单击左侧的本地链接(例如“状态”),它会生成一个 URL “http://myhost.com/manager/status”,而应该 生成:“http://myhost.com/myapp/manager/status”

(对于安装在tomcat下的webapps也是如此)

我的配置(apache,tomcat?)中应该更改什么才能将我的tomcat链接重定向到正确的位置?

I've set up a host with apache to serve static pages and to use Tomcat to serve my web application (See this question). The static pages are server from

"http://myhost.com"

and the dynamic (tomcat) pages are server from

"http://myhost.com/myapp"

The mod_proxy makes sure the "http://myhost.com/myapp" are forwarded to tomcat server running on "http://myhost.com:8080".

The problem is that now you get the standard Tomcat introduction page on "http://myhost.com/myapp" but if you click on a local link (e.g. 'Status') on the left, it generates an URL
"http://myhost.com/manager/status" while it should generate: "http://myhost.com/myapp/manager/status"

(The same is true for webapps installed under tomcat)

What should be changed in my configuration (apache, tomcat?) to redirect my tomcat links to the right place?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心碎的声音 2024-08-25 10:42:31

您是否设置了 ProxyPassReverse在您的 httpd.conf 中进行设置。这将覆盖 HTTP 标头,您将在 tomcat 方面获得正确的请求。

Have you set the ProxyPassReverse setting in your httpd.conf. This will overwrite the HTTP Header an you'll get to the correct request on the side of tomcat.

生生漫 2024-08-25 10:42:31

您的网址映射自:

http://myhost.com/myapp -> http://myhost.com:8080

表示访问上述URL将会被映射到ROOT应用中雄猫。 ROOT 应用程序将生成包含来自 Tomcat 根上下文的链接的页面。

换句话说,如果您访问:

http://myhost.com:8080

您将看到一个页面包含指向

http://myhost.com:8080/manager/status

的链接此链接有效。然而,当该页面返回给通过 Apache 请求该页面的浏览器时,完整的 URL 如下所示: http:// /myhost.com/manager/status

我假设您打算将名为“myapp”的应用程序部署到 Tomcat?如果是这种情况,此应用程序的 Tomcat URL 将为

http://myhost.com:8080/myapp

通过 Apache 访问时也能正确映射。

如果您绝对必须以这种方式访问​​ Tomcats 根应用程序,则必须重写它在返回的页面中输出的 URL。

Your URLs are mapped from:

http://myhost.com/myapp -> http://myhost.com:8080

This means that accessing the above URL will be mapped to the ROOT application in Tomcat. The ROOT application will generate pages that contain links from Tomcat's root context.

In other words, if you go to:

http://myhost.com:8080

you will get a page that contains links to

http://myhost.com:8080/manager/status

This link will work. However when that page is given back to a browser that requested it via Apache, the full URL then looks like: http://myhost.com/manager/status

I assume that you intend to deploy an application called 'myapp' to Tomcat? If that is the case the Tomcat URL for this app will be

http://myhost.com:8080/myapp

Which will also work be mapped correctly when accessed via Apache.

If you absolutely must access Tomcats root application in this way you'll have to rewrite the URLs it outputs in the pages it returns.

月下客 2024-08-25 10:42:31

我在 mod_proxy_ajp 方面取得了最大的成功。它需要 mod_proxy,但可以通过 ajp 运行。使用它,您的conf文件看起来类似

    ProxyPass / ajp://localhost:8009/

请参阅我的类似的问题以及的答案这个问题。我发现 mod_proxy_ajp 中唯一的错误是,如果我需要重新启动 tomcat,我也必须强制重新启动 apache。

I've had the most success with mod_proxy_ajp. It requires mod_proxy, but works over ajp. Using it instead, your conf file looks similar

    ProxyPass / ajp://localhost:8009/

See my similar question and also the answer to this question. The only fault in mod_proxy_ajp that I've found is that if I need to restart tomcat I have to force an apache restart too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文