server.xml引入子文件配置(tomcat虚拟主机)

  • A+
Categories:Linux

在配置tomcat虚拟主机时候,如何每一个虚拟主机写成单独文件,server.xml包含这些子文件? 如以下《OneinStack》中,添加JAVA环境虚拟主机后tomcat配置文件详情:

/usr/local/tomcat/conf/server.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE server-xml [
  3. <!ENTITY localhost-vhost SYSTEM "file:///usr/local/tomcat/conf/vhost/localhost.xml">
  4. <!ENTITY java.linuxeye.com-vhost SYSTEM "file:///usr/local/tomcat/conf/vhost/java.linuxeye.com.xml">
  5. <!ENTITY demo.linuxeye.com-vhost SYSTEM "file:///usr/local/tomcat/conf/vhost/demo.linuxeye.com.xml">
  6. ]>
  7. <Server port="8006" shutdown="SHUTDOWN">
  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.   <Listener className="org.apache.catalina.core.AprLifecycleListener"/>
  12. <!--
  13.   <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="8081" rmiServerPortPlatform="8082" />
  14. -->
  15.   <GlobalNamingResources>
  16.     <Resource name="UserDatabase" auth="Container"
  17.               type="org.apache.catalina.UserDatabase"
  18.               description="User database that can be updated and saved"
  19.               factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  20.               pathname="conf/tomcat-users.xml" />
  21.   </GlobalNamingResources>
  22.   <Service name="Catalina">
  23.     <Connector port="8080"
  24.               protocol="org.apache.coyote.http11.Http11AprProtocol"
  25.               connectionTimeout="20000"
  26.               redirectPort="8443"
  27.               maxThreads="1000"
  28.               minSpareThreads="20"
  29.               acceptCount="1000"
  30.               debug="0"
  31.               disableUploadTimeout="true"
  32.               useBodyEncodingForURI="true"
  33.               enableLookups="false"
  34.               URIEncoding="UTF-8" />
  35.     <Engine name="Catalina" defaultHost="localhost">
  36.       <Realm className="org.apache.catalina.realm.LockOutRealm">
  37.         <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  38.                resourceName="UserDatabase"/>
  39.       </Realm>
  40.       &localhost-vhost;
  41.       &java.linuxeye.com-vhost;
  42.       &demo.linuxeye.com-vhost;
  43.     </Engine>
  44.   </Service>
  45. </Server>

注:在<server>元素前添加如下格式:

  1. <!DOCTYPE server-xml [
  2.   <!ENTITY localhost-vhost SYSTEM "file:///usr/local/tomcat/conf/vhost/localhost.xml">
  3. ]>

并在<Engine>...</Engine]引用它(localhost-vhost,注:不能以数字开头)即可。

下面是每个单独虚拟主机文件:/usr/local/tomcat/conf/vhost/localhost.xml

  1. <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
  2.   <Context path="" docBase="/data/wwwroot/default" debug="0" reloadable="true" crossContext="true"/>
  3.   <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  4.          prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />

/usr/local/tomcat/conf/vhost/demo.linuxeye.com.xml

  1. <Host name="demo.linuxeye.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
  2.   <Context path="" docBase="/data/wwwroot/demo.linuxeye.com" debug="0" reloadable="true" crossContext="true"/>
  3.   <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  4.          prefix="demo.linuxeye.com_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />

/usr/local/tomcat/conf/vhost/java.linuxeye.com.xml

  1. <Host name="java.linuxeye.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Alias>java1.linuxeye.com</Alias>
  2.   <Context path="" docBase="/data/wwwroot/java.linuxeye.com" debug="0" reloadable="true" crossContext="true"/>
  3.   <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  4.          prefix="java.linuxeye.com_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  5. </Host>
Wed Sep  2 14:06:44 CST 2015

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: