【发布时间】:2014-02-18 13:53:41
【问题描述】:
基本上我有一个apache服务器和一个tomcat服务器在同一台机器上运行,当我的tomcat服务器收到请求时,根据请求的内容类型,我想将请求传输到apache服务器。
我知道的一种方法是创建到 apache 服务器的 URL 连接并将数据写入客户端流,我想知道是否有更好的方法来做到这一点?
【问题讨论】:
基本上我有一个apache服务器和一个tomcat服务器在同一台机器上运行,当我的tomcat服务器收到请求时,根据请求的内容类型,我想将请求传输到apache服务器。
我知道的一种方法是创建到 apache 服务器的 URL 连接并将数据写入客户端流,我想知道是否有更好的方法来做到这一点?
【问题讨论】:
另一种选择是将请求重定向到 apache。您可以通过添加路径作为 ProxyPass 来做到这一点。
# you probably have something like this in there right now
ProxyPass / ajp://127.0.0.1:8009/
# this will tell apache to not proxy the /http/* path
ProxyPass /http !
# you then make an alias to your web files you want to path to
Alias /http "C:/htdocs"
<Directory "C:/htdocs">
AllowOverride All
Require all granted
</Directory>
当然,/http 可以是您想要的任何路径。通过 Apache 端的设置,您可以将请求重定向到子路径。
@RequestMapping("/myPage")
public String viewPage(HttpServletRequest request, HttpServletResponse response) {
if(/*stuff*/) {
// forward to the same path but with /http prepended
return "forward:/http"+request.getRequestURI();
}
return "myPage";
}
【讨论】: