java - 将请求从tomcat传输到apache

标签 java apache tomcat

基本上我有一个 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/

相关文章:

java - java ab中动态绑定(bind)和签名方法的问题

java - 将集合(ArrayList)添加到ConcurrentQueue

apache - apache错误的logstash grok模式是什么?

php - 如何检测 PHP 中的 X-Accel-Redirect (Nginx)/X-Sendfile (Apache) 支持?

java - 失败 - 如果在 server.xml 中定义了上下文,则无法上传 War 文件 "cms.war"

java - Android 对话框显示空弹出窗口

java - 文件名前缀上的 Camel 路由

apache - 如何将 Apache 日志重定向到 STDOUT 和 Apache 日志文件

java - Spring Tomcat和静态资源和mvc :resources

跨 AWS 集群的 Spring、Tomcat 8 Ehcache 复制(在 EC2 实例上)