基本上我有一个 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";
}
关于java - 将请求从tomcat传输到apache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21385728/