如何在不同端口上运行的tomcat中部署多个Web应用程序? [英] How to deploy mutiple web application in tomcat which will run on different ports?

查看:170
本文介绍了如何在不同端口上运行的tomcat中部署多个Web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不同端口上运行的tomcat中部署多个java Web应用程序?
- 如何进行设置以便在不同的端口上运行不同的Web应用程序
- 为实现这一目标需要做些什么?

How to deploy mutiple java web application in tomcat which will run on different ports ? - How to do settings so that different web application will run on differet ports - What all needs to be done for achieving this ?

推荐答案

您需要在server.xml文件(tomcat_home / conf)中设置另一个服务。如果你没有更改你的服务器文件,你应该已经有一个名为Catalina的(我使用的是Tomcat 5.5,根据版本可能略有不同)

You will need to setup another service in your server.xml file (tomcat_home/conf). If you havent changed your server file, you should already have one named Catalina (I am using Tomcat 5.5, you may have something slightly different depending on version)

<Service name="Dev2">
    <Connector port="8090" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
    <Connector port="8092" 
               enableLookups="false" redirectPort="9443" protocol="AJP/1.3" />

    <Engine name="Dev2" defaultHost="MyDev">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>
      <Host name="MyDev" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
      </Host>
    </Engine>
</Service>

请注意,名称已从Catalina更改为Dev2,localhost更改为MyDev。将这些更改为适合您的应用程序的任何内容。端口和连接器也发生了变化。
设置新服务后,您需要将应用程序部署到正确的服务/端口。您可以通过使用XML文件来完成此任务(请参阅虚拟主机

Notice that the names have changed from Catalina to Dev2, and localhost to MyDev. Change these to whatever you seem fit for your application. The ports and connectors have also changed. Once the new Service is setup, you then need to deploy applications to the proper Service/Port. You accomplish this by using XML files under (See Virtual Hosting )

Tomcat_Home/conf/Catalina/localhost/

Tomcat_Home/conf/Dev2/MyDev/

您正在设置的各个端口

At这一点,您只需添加一些文件即可将服务指向您的应用程序。
例如,在下Tomcat_Home / conf / Dev2 / MyDev / 我有一个名为Another.xml的文件这个文件包含以下内容

At this point all you have to do is add a few more files to point the Service to your application. As an Example, under Tomcat_Home/conf/Dev2/MyDev/ I have a file called Another.xml This file contains the following

<Context path="/" docBase="C:/to_delete" debug="10" crossContext="false">
</Context>

现在我可以使用网址 http://访问新应用程序127.0.0.1:8090/另一个
如果我尝试使用默认端口8080访问它,我会收到一个错误,因为没有为该给定端口部署应用程序。

Now I can access the new application using the web address http://127.0.0.1:8090/Another If I try and access this using my default port of 8080, I get an error as the application was not deployed for that given port.

关于此设置的注意事项很少。如果使用VirtualVM查看应用程序,您会注意到它们共享相同的进程ID。因此,您必须格外小心您的资源。它们将使用相同的Heap空间,并且所有线程将显示在同一列表中。如果您已登录您的应用程序(即Log4j),请确保您可以选择显示正在执行哪个线程的工作,因为可能很难告诉它将来自哪个端口/应用程序。

Few things to note about this setup. If you use VirtualVM to look at the application, you will notice that they share the same process ID. Therefore you have to be extra careful of your resources. They will be using the same Heap space, and all the threads will be showing in the same list. If you have logging in your applications (i.e Log4j) ensure you have an option to show which thread was doing the work, as it may be tough to tell otherwise which port/application this would be coming from.

正如Bozho已经指出的那样,简单地让两个Tomcat实例运行而不是一个服务器监听多个端口可能更容易。

As Bozho has already pointed out, It may be easier to simply have two instances of Tomcat running instead of one server listening on multiple ports.

这篇关于如何在不同端口上运行的tomcat中部署多个Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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