在Apache中如何使用相同的上下文根来定义多个ProxyPass到不同的服务器?

**更新与解决方法在这个答案的底部**

我有一个要求我的web应用程序代理到2个外部报告服务器。 所以我将为每个外部报告服务器提供一个菜单项。

但是,浏览器的URL也看起来像我的服务器,所以我不能只是redirect。 这些服务器都具有相同的上下文根/ ibm

对于这两个服务器,浏览器URL应该看起来像http://example.com/ibm ,而apache代理正确的。

应该如何做这样的设置? Apache如何知道它必须代理哪个?

如果我不得不做一些改变,那么URL将会变成:

http://example.com/rep1/ibm and http://example.com/rep2/ibm 

我设法使用我的weblogic-proxy servlet和操作URL等来达到预期的效果,但是如果可以以某种方式完成,Apache将是一个更高效的解决scheme。

我很欣赏任何input。

此外,对外部报告服务器的初始请求是从我的web应用程序启动,而不是从浏览器启动。

**更新**

我们现在必须代理约10个其他的networking服务器,其中一些有这个问题。 但是每当目标web服务器被部署在根目录中时,我们也必须重写主体等等。对于这些代理集成中的一些来说,这是一个试验和错误。

解决方法:我们已经切换到这些代理服务器的子域,实际上子域URL仍然指向我们自己的Apache,但是使用这些子域名,我们可以更容易地在我们的Apacheconfiguration中设置一个虚拟主机和代理服务器,我们不必重写任何响应机构等。

这很容易用mod_proxy完成:

 ProxyPass /rep1/ibm http://reportingserver1.example.com/ibm ProxyPassReverse /rep1/ibm http://reportingserver1.example.com/ibm ProxyPass /rep2/ibm http://reportingserver2.example.com/ibm ProxyPassReverse /rep2/ibm http://reportingserver2.example.com/ibm 

有更多的信息在mod_proxy的apache文档站点 。

如果您需要更改从外部网站返回的内容中的链接,可以使用mod_ext_filter来完成 。 以下是重写链接的示例configuration:

 # mod_ext_filter directive to define a filter which # replaces text in the response # # Note: I'm Using a '#' instead of an '/' in the sed command since I want to # include '/' in the string # ExtFilterDefine rep1 mode=output intype=text/html \ cmd="/bin/sed s#reportingserver1.example.com/ibm#example.com/rep1/ibm#g" <Location /rep1> # core directive to cause the fixtext filter to # be run on output SetOutputFilter rep1 ProxyPass /rep1/ibm http://reportingserver1.example.com/ibm ProxyPassReverse /rep1/ibm http://reportingserver1.example.com/ibm </Location> 

我现在可以使用反向代理的mod_proxy和带有ProxyHTMLURLMap的mod_proxy_html的组合来重写返回的内容。 初始页面加载OK和所有的URL等被重写,他们显示rep1的前缀,当我胡佛。

但是当我点击代理应用程序中的某个菜单时,我认为正在完成一个Ajax请求,并且返回的页面将被插入。 但是我正面临一个问题,即返回的内容被"<html><body>"标签包围。 并因为这个页面不更新我想。

我试图找出如何可以阻止proxy_html这样做。

我目前的configuration:

 ProxyPass /MD/ http://xx.xxx.xxx.xx:8080/ <Location /MD/> ProxyHTMLURLMap /ibm/ /MD/ibm/ ProxyHTMLURLMap /mum/ /MD/mum/ ProxyPassReverse / RequestHeader unset Accept-Encoding ProxyHTMLEnable On #ProxyHTMLInterp On ProxyHTMLEvents On ProxyHTMLExtended On #SetOutputFilter DEFLATE #SetOutputFilter INFLATE;proxy-html;DEFLATE #SetOutputFilter INFLATE;proxy-html;SUBSTITUTE;DEFLATE #SetOutputFilter proxy-html #ProxyHTMLBufSize 6000000 #ProxyHTMLMeta On ProxyHTMLLinks a href ProxyHTMLLinks area href ProxyHTMLLinks link href ProxyHTMLLinks img src longdesc usemap ProxyHTMLLinks object classid codebase data usemap ProxyHTMLLinks q cite ProxyHTMLLinks blockquote cite ProxyHTMLLinks ins cite ProxyHTMLLinks del cite ProxyHTMLLinks form action ProxyHTMLLinks input src usemap ProxyHTMLLinks head profile ProxyHTMLLinks base href ProxyHTMLLinks script src for ProxyHTMLLinks frame src longdesc ProxyHTMLLinks iframe src longdesc ProxyHTMLLinks body background ProxyHTMLLinks applet codebase ProxyHTMLCharsetOut * ProxyHTMLEvents onclick ondblclick onmousedown onmouseup onmouseover onmousemove onmouseout onkeypress onkeydown onkeyup onfocus onblur onload onunload onsubmit onreset onselect onchange </Location>