标签:deploy event deb 监听 prefix 声明 host cycle userdata
tomcat原始server.xml配置文件如下(删除注释):
1 <?xml version=‘1.0‘ encoding=‘utf-8‘?> 2 3 <Server port="8005" shutdown="SHUTDOWN"> 4 <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> 5 6 <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 7 <Listener className="org.apache.catalina.core.JasperListener" /> 8 <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 9 <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 10 <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> 11 12 13 <GlobalNamingResources> 14 15 <Resource name="UserDatabase" auth="Container" 16 type="org.apache.catalina.UserDatabase" 17 description="User database that can be updated and saved" 18 factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 19 pathname="conf/tomcat-users.xml" /> 20 </GlobalNamingResources> 21 22 23 <Service name="Catalina"> 24 25 <Connector port="8080" protocol="HTTP/1.1" 26 connectionTimeout="20000" 27 redirectPort="8443" /> 28 29 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 30 31 <Engine name="Catalina" defaultHost="localhost"> 32 33 <Realm className="org.apache.catalina.realm.LockOutRealm"> 34 <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 35 resourceName="UserDatabase"/> 36 </Realm> 37 38 <Host name="localhost" appBase="webapps" 39 unpackWARs="true" autoDeploy="true"> 40 41 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 42 prefix="localhost_access_log." suffix=".txt" 43 pattern="%h %l %u %t "%r" %s %b" /> 44 45 </Host> 46 47 </Engine> 48 </Service> 49 </Server>
简单说明:配置文件中server组件只能有一个,service可以有多个,每个service里面有多个connector(连接器)和一个Engine容器,连接器监听端口,接收请求后生成request和response对象并将请求交给Engine容器处理,Engine有一个默认虚拟主机对应host容器(该容器在配置文件中必须声明),Engine根据域名找到对应的host,host容器会根据请求路径找到对应的context容器(稍后说明)。比如说请求地址为 http://localhost:8080/webapp1连接器监听的8080端口有请求,Engine将请求送到name=localhost的host容器,host容器再根据/webapp1找到具体的web项目。
tomcat部署方式(详情可自行百度)
自动部署:~
手动部署:显示的在server.xml里面配置context容器
同一个tomcat下部署多个web项目的几种方式
1、配置多个service实现“同一域名不同端口号”访问不同web项目
2、配置多个host实现“不同域名同一端口号”访问不同web项目,server.xml文件如下
1 <?xml version=‘1.0‘ encoding=‘utf-8‘?> 2 3 <Server port="8005" shutdown="SHUTDOWN"> 4 <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> 5 6 <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 7 <Listener className="org.apache.catalina.core.JasperListener" /> 8 <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 9 <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 10 <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> 11 12 13 <GlobalNamingResources> 14 15 <Resource name="UserDatabase" auth="Container" 16 type="org.apache.catalina.UserDatabase" 17 description="User database that can be updated and saved" 18 factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 19 pathname="conf/tomcat-users.xml" /> 20 </GlobalNamingResources> 21 22 23 <Service name="Catalina"> 24 25 <Connector port="8080" protocol="HTTP/1.1" 26 connectionTimeout="20000" 27 redirectPort="8443" /> 28 29 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 30 31 <Engine name="Catalina" defaultHost="localhost"> 32 33 <Realm className="org.apache.catalina.realm.LockOutRealm"> 34 <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 35 resourceName="UserDatabase"/> 36 </Realm> 37 38 <Host name="localhost" appBase="webapps" 39 unpackWARs="true" autoDeploy="true"> 40 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 41 prefix="localhost_access_log." suffix=".txt" 42 pattern="%h %l %u %t "%r" %s %b" /> 43 44 </Host> 45 46 <Host name="www.test1.com" appBase="webapps" 47 unpackWARs="true" autoDeploy="true"> 48 49 <Context path ="" docBase ="/test1" debug ="0" reloadbale ="true" ></Context> 50 51 </Host> 52 53 <Host name="www.test2.com" appBase="webapps" 54 unpackWARs="true" autoDeploy="true"> 55 56 <Context path ="" docBase ="/test2" debug ="0" reloadbale ="true" ></Context> 57 58 </Host> 59 </Engine> 60 </Service> 61 </Server>
可以通过 www.test1.com:8080访 “tomcat根目录/webapps”下的test1项目。通过 www.test2.com:8080访 “tomcat根目录/webapps”下的test2项目。
简单说明:context容易中,path表示访问项目的路径,这里为空,若不为空如path ="test",那么需要在浏览器中输入www.test1.com:8080/test才能访问项目;docbase表示项目实际存放位置。
注意:自行修改hosts文件实验,http默认端口号是80,若想要直接通过www.test1.com域名访问test1项目,只需server.xml添加如下
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
3、配置多个context实现“同一域名同一端口号不同项目路径”访问不同web项目。
标签:deploy event deb 监听 prefix 声明 host cycle userdata
原文地址:http://www.cnblogs.com/ouym/p/7499019.html