我似乎没有得到如何正确configurationReverseProxy。 返回的URL全部为根目录“/”,而不是“/ tomcat”,只显示主“默认”的tomcat页面。 我使用以下代理规则将Apache2作为Tomcat的前端:
ProxyPass /tomcat ajp://127.0.0.1:8009/ ProxyPassReverse /tomcat ajp://127.0.0.1:8009/
我也尝试在Tomcat的AJP连接器设置中使用ProxyName。 使用mod_rewrite代理AJP请求也给出了相同的结果。
Apache error.log提供以下行(尝试从自己的根加载图像):
File does not exist: /var/www/asf-logo-wide.gif, referer:
编辑:AJP工程通过mod_jk,但使用子文件夹时仍然得到HTTP相同的问题。
问题是你的tomcat服务器将链接embedded到HTML知道的path中。 不是您的代理服务器的path。 (从你的* .gif日志条目中得到这个)
ProxyPassReverse不会修改HTML中的链接。 它只修改HTTP头。
为了使这个工作,你需要在应用程序的上下文中configuration适当的位置和path的tomcat。 很可能,您需要将webapp.war文件重命名为ROOT.war,并将任何上下文configuration更改为“/”。
您可以尝试这篇文章,它解释了使用ProxyPassReverse的正确方法:
http://www.humboldt.co.uk/2009/02/the-mystery-of-proxypassreverse.html
如果您需要返回到mod_proxy :
<Location /tomcat> ProxyPass ajp://127.0.0.1:8009/tomcat ProxyPassReverse ajp://127.0.0.1:8009/tomcat </Location>
由于您输出的绝对URLs有多种常见的情况:
使用mod_proxy_html 。
或者你可以使用RewriteEngine来重写URL到/myapp/ 。
RewriteEngine On RewriteCond %{REQUEST_URI} ! ^/myapp/ RewriteRule ^/(.*)$ /myapp/$1
这是来自内存,所以你可能想通过mod_rewrite文档自己validation。 但是我build议坚持使用mod_proxy_html因为重写发送给客户端的链接并不比在内部重写每个请求复杂。