测试了一下tomcat配置不同应用的不同端口的配置方式,下面做一个conf/server.xml配置结果的记录
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8088" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Alias>www.test3.com</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="D:\TomCat7.0\testapp\TestWebliu" />
</Host>
</Engine>
</Service>
<Service name="Catalina2">
<Connector port="880" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina2" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="D:\TomCat7.0\testapp\TestWebliu" />
</Host>
<Host name="www.test2.com" appBase="testapp"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="D:\TomCat7.0\testapp\TestWebliu" />
</Host>
</Engine>
</Service>
</Server>
该server下面两个service节点,每个service节点可以用Connector配置一个监听端口,service里有只能有一个Engine节点,它接受同级目录Connector端口的请求,可以通过defaultHost属性默认指向一个Host,Host就是一个该Connector端口下的域名
即:server下面可以有多个service,用于配置不同监听端口,每个service代表一个应用(只能配置两个service)
service下面可以有多个Host,用于配置该端口下的不同域名
上面的配置,可以用下面链接访问:
test2,3都是hosts里指向了本地的。
Host下的Alias是一个域名别称。
Host下面的context节点配置为:<Context path="" 后,则这个目录为默认的访问目录,比如http://www.test2.com:880/,访问的D:\TomCat7.0\testapp\TestWebliu下面的文件。