我已经使用 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?
发布评论
评论(3)
您是否设置了
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.您的网址映射自:
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.
我在
mod_proxy_ajp
方面取得了最大的成功。它需要 mod_proxy,但可以通过 ajp 运行。使用它,您的conf文件看起来类似请参阅我的类似的问题以及的答案这个问题。我发现 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 similarSee 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.