将多个应用程序部署到 Tomcat [英] deploying multiple applications to Tomcat

查看:41
本文介绍了将多个应用程序部署到 Tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将两个应用程序 foo.warbar.war 部署到同一个 Tomcat 实例.他们是否可以侦听不同端口上的连接,例如foo 侦听端口 81 而 bar 侦听端口 82?如果是这样,我该如何配置?我意识到应用程序没有必要侦听不同的端口,但这正是我想要实现的.

I want to deploy two applications foo.war and bar.war to the same Tomcat instance. Is it possible for them to listen for connections on different ports, e.g. foo listens on port 81 and bar listens on port 82? If so, how can I configure this? I realise that it is not necessary for the applications to listen on different ports, but that is what I want to achieve.

另外,如果我将 foo.war 重命名为 ROOT.war 使其在根上下文中运行,那么我对这个 Tomcat 的所有请求是否正确实例将由 foo 应用程序处理,因此必须将 bar 部署到单独的 Tomcat 实例?

Also, am I right in saying that if I rename foo.war to ROOT.war such that it runs in the root context, then all requests to this Tomcat instance will be handled by the foo app and therefore bar would have to be deployed to a separate Tomcat instance?

推荐答案

如果想让Tomcat监听多个端口,就需要为每个端口设置一个connector.要将每个端口映射到不同的应用程序,您需要将每个连接器包装在一个 service 中,并使用它自己的 appBase 创建一个 host.

If you want Tomcat to listen to multiple ports, you need to setup a connector for each port. To get each port mapped to a different application, you need need to wrap each connector in a service and create a host with it's own appBase.

server.xml 中的服务定义示例:

<Service name="foo">
    <Connector port="80" protocol="org.apache.coyote.http11.Http11NioProtocol" />
    <Engine name="Catalina80" defaultHost="localhost">
        <Host name="localhost" appBase="foo" unpackWARs="true" autoDeploy="true" />
    </Engine>
</Service>

<Service name="bar">
    <Connector port="81" protocol="org.apache.coyote.http11.Http11NioProtocol" />
    <Engine name="Catalina81" defaultHost="localhost">
        <Host name="localhost" appBase="bar" unpackWARs="true" autoDeploy="true" />
    </Engine>
</Service>

您需要为端口 80bar 创建目录 foo,而不是将 war 文件放到 webapps 目录中 用于端口 81.将两个战争文件命名为 ROOT.war 并将它们放在自己的基本目录中.如果需要,您当然可以在每个目录中有多个应用.

Instead of dropping the war files in the webapps directory, you need to create the directory foo for port 80 and bar for port 81. Name both war files ROOT.war and drop them in their own base directory. You can of course have multiple apps in each directory if you need.

appBase中定义的目录是相对于tomcat目录的.通过使用绝对路径,它可以位于您系统的任何位置.来自文档:

The directory defined in appBase is relative to the tomcat directory. By using an absolute path, it could be anywhere on your system. From the documentation:

appBase

此虚拟主机的Application Base 目录.这是可能包含要在此虚拟主机上部署的 Web 应用程序的目录的路径名.您可以指定绝对路径名或相对于 $CATALINA_BASE 目录的路径名.[...] 如果未指定,将使用默认的 webapps.

The Application Base directory for this virtual host. This is the pathname of a directory that may contain web applications to be deployed on this virtual host. You may specify an absolute pathname, or a pathname that is relative to the $CATALINA_BASE directory. [...] If not specified, the default of webapps will be used.

另一种选择是保留默认的 tomcat 配置并使用另一个 http 服务器(apache、nginx、lighttpd...)将端口映射到 tomcat 应用程序的内部路径.

Another option is to keep the default tomcat configuration and use another http server (apache, nginx, lighttpd,...) to map a port to the internal path of a tomcat application.

根应用程序不会收到与其他应用程序匹配的请求,例如/foo/example 将转到 foo.war/example/example 将转到 ROOT.war.

The root application won't receive requests that match other applications, e.g. /foo/example will go to foo.war, /example/example will go to ROOT.war.

这篇关于将多个应用程序部署到 Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆