1.通过配置多个<Context>元素(不同目录)
(fatkun:这个和直接放在webapps不用配置差不多)
在<Host>下配置多个<Context>元素
1
2
| <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>元素(不同域名)
1
2
3
4
5
6
| <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>元素(不同端口)
在<Server>下配置多个<Service>元素
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| <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