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

Linux评论9阅读模式

在配置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

 
  • 本文由 yeho 发表于 2015-09-02
  • 转载请务必保留本文链接:https://linuxeye.com/429.html
Tomcat日志切割(logrotate) Linux

Tomcat日志切割(logrotate)

logrotate是个强大的系统软件,它对日志文件有着一套完整的操作模式,譬如:转储、邮件和压缩等,并且默认logrotate加到cron(/etc/cron.daily/logrotate)作为每日...
脚本

Tomcat启动脚本

记录一个比较好的tomcat启动脚本,截取《OneinStack》,修改如下两个参数即可用。 使用之前修改下面2个参数: #Location of JAVA_HOME (bin files) expo...
匿名

发表评论

匿名网友
确定

拖动滑块以完成验证