Tomcat建立多个虚拟主机,只须要修改server.xml,添加多个的Host,指定不一样的name便可。 html
Tomcat的server.xml文件Host内容解析: web
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
在server.xml中使用<Host>标签包裹,其中Host标签的元素有: apache
name : 指出这个虚拟主机的名字,能够使域名。 tomcat
appBase : 若是要war文件自动部署的话指定这个目录,这个目录下的war文件会被自动部署。 app
unpackWARs : 是否对appBase指定的目录下的war文件自动解压,true为自动解压,false为不自动解压,直接运行war文件。 webapp
autoDeploy:设置是否在tomcat运行期间自动更新项目(包括在appBase添加新的项目,修改,删除,更新),true时,会自动更新appBase下的war项目,web.xml文件的更改,以及Host下指定<Context> 标签订制的项目(在appBase下的)。 网站
(http://tomcat.apache.org/tomcat-7.0-doc/deployer-howto.html#Deploying_on_a_running_Tomcat_server) ui
在Host标签中,还能够添加子标签: url
<Alias>域名</Alias> spa
指定域名,可设置多个。支持正则.
<Context path="" docBase="/www/a.war" reloadable="true" />
context标签是用来指定自定义的网站的url,以及映射实际的在系统的物理路径。
例如:<Context path="/abc" docBase="/www/a.war" reloadable="true" />时,咱们访问www.xxx.com/abc代替www.xxx.com/a。
path :是要重命名后的路径,用/表明根路径,例如/abc
docBase: 是指定war的真实的物理路径,能够不在appBase下。
reloadable:为true时会自动更新,context指定的应用。
关于appBase和docBase路径的区别和关系:
appBase:是能够自动部署war的路径,默认是在tomcat的安装路径下的webapps,若是 用tomcat的默认的话使用相对路径,也能够使用绝对路径指定一个非tomcat默认的路径。
docBase:与appBase没什么直接关系,它指出特定的应用的单独设置。若是war包在 appbase下,能够使用相对路径,好比在appBase路径下有,a.war,设置 docBase时能够用a来设置。经常使用使用绝对路径定义。
标签:Valve:
设置Host的访问日志
classname : 设置使用哪一个类来处理tomcat的访问日志
directory : 设置log日志的存放路径,默认log是在tomcat的安装路径下logs目录下
prefix : 指定访问日志的前缀,也能够理解为名字。
suffix : 指定访问日志的后缀,能够理解为扩展名。
pattern : 为日志的记录格式。