用一个Tomcat建立多个Server

1.通过配置多个元素(不同目录)

(fatkun:这个和直接放在webapps不用配置差不多) 在下配置多个元素

<Context path="app1" docBase="E:/workspace/app1/WebRoot" debug="0" reloadable="true"></Context>
<Context path="app2" docBase="E:/workspace/app2/WebRoot" debug="0" reloadable="true"></Context>

然后通过 主机名:端口/应用名 访问,如: http://localhost:8080/app1 或 http://localhost:8080/app2

2.通过配置多个元素(不同域名)

<Host appBase="webapps" name="192.168.1.110">
   <Context path="" docBase="E:/workspace/app1/WebRoot" debug="0" reloadable="true"></Context>
  </Host>
  <Host appBase="webapps" name="192.168.1.114">
   <Context path="" docBase="E:/workspace/app2/WebRoot" debug="0" reloadable="true"></Context>
  </Host>

然后通过 主机名:端口 访问,如: http://192.168.1.110:8080 或 http://192.168.1.114:8080
name中的192.168.1.110可以是你的域名或者需要绑定的IP

3.通过配置多个元素(不同端口)

下配置多个元素

<Service name="Catalina1">
    <Connector port="90" protocol="HTTP/1.1"  connectionTimeout="20000"  redirectPort="8443" URIEncoding="gbk" />
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
    <Engine name="Catalina2" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"  resourceName="UserDatabase"/>
      <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true"  xmlValidation="false" xmlNamespaceAware="false">
			<Context path="" docBase="F:/workspace/app1/WebRoot" debug="0" reloadable="true"></Context>
      </Host>
    </Engine>
  </Service>
  <Service name="Catalina2">
    <Connector port="91" protocol="HTTP/1.1"  connectionTimeout="20000"  redirectPort="8443" URIEncoding="gbk" />
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
    <Engine name="Catalina2" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"  resourceName="UserDatabase"/>
      <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true"  xmlValidation="false" xmlNamespaceAware="false">
			<Context path="" docBase="F:/workspace/app2/WebRoot" debug="0" reloadable="true"></Context>
      </Host>
    </Engine>
  </Service>

定义了两个Service分别是Catalina和Catalina2,侦听的端口分别是90和91
然后通过 主机名:端口 访问,如: http://localhost:90 或 http://localhost:91 原文来自:http://www.blogjava.net/siyn/archive/2008/07/07/213133.html

updatedupdated2024-11-302024-11-30