注意 | |
---|---|
Tomcat 8 取消了 xmlValidation="false" xmlNamespaceAware="false" 两个配置项。 |
appBase 是防止 war 文件的扫描目录。
将配置写入server.xml文件
<Host name="www.example.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="" docBase="/www/example.com/www.example.comm" debug="0" reloadable="false"/> </Host> <Host name="news.example.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="" docBase="/www/example/news.example.com" debug="0" reloadable="false"/> </Host>
在 $CATALINA_HOME/conf/Catalina/ 下创建配置文件
vim server.xml <Engine name="Catalina" defaultHost="neo"> <Host name="neo" appBase="webapps"/> <Host name="other" appBase="webapps"/> </Engine>
Webapps Directory
mkdir $CATALINA_HOME/conf/Catalina/neo
Configuring Your Contexts
mkdir $CATALINA_HOME/conf/Catalina/neo cp $CATALINA_HOME/conf/Catalina/localhost/manager.xml $CATALINA_HOME/conf/Catalina/neo/ROOT.xml or cp $CATALINA_HOME/conf/Catalina/localhost/manager.xml $CATALINA_HOME/conf/Catalina/neo
别名的功能是为虚拟主机绑定多个域名
<Host name="www.example.com" debug="9" appBase="webapps" unpackWARs="false" autoDeploy="false" xmlValidation="false" xmlNamespaceAware="false"> <Alias>www.example.net</Alias> <Alias>exmaple.com</Alias> <Alias>224.25.22.70</Alias> </Host>
<Host name="localhost" ...> ... <Valve className="org.apache.catalina.valves.AccessLogValve" prefix="localhost_access_log." suffix=".txt" pattern="common"/> ... </Host>
<Valve className"org.apache.catalina.valves.AccessLogValve" directory="logs/access" prefix="www.netkiller.cn.access" suffix=".log" pattern="%{X-Forwarded-FOR}i %a %v %U %t %m %s %{User-Agent}i" resolveHosts="false"/>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/> <Context docBase="Struts" path="/Struts" reloadable="true" source="org.eclipse.jst.jee.server:Struts"/> </Host>
docBase如果是绝对路径就会忽略appBase="webapps"的设置。
<Context path="" docBase="/www/example.com/www.example.com/WebContent" reloadable="false">
appBase + docBase 方案
<Host name="localhost" appBase="/www/example.com" unpackWARs="true" autoDeploy="true"> <Alias>www.example.com</Alias> <Context path="" docBase="www.example.com" reloadable="false"></Context> </Host>
<Host name="223.225.22.72" appBase="/www/netkiller.cn" unpackWARs="true" autoDeploy="true"> <Alias>www.netkiller.cn</Alias> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="www.netkiller.cn_access_log." suffix=".log" pattern="%h %l %u %t "%r" %s %b" /> <Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="web_log." suffix=".txt" timestamp="true"/> <Context path="" docBase="www.netkiller.cn" reloadable="true"></Context> </Host> <Host name="223.225.22.73" appBase="/www/netkiller.cn" unpackWARs="true" autoDeploy="true"> <Alias>admin.netkiller.cn</Alias> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="admin.netkiller.cn_access_log." suffix=".log" pattern="%h %l %u %t "%r" %s %b" /> <Context path="" docBase="admin.netkiller.cn" reloadable="true" /> </Host>
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。