在网络上看了许久,没有一个真正可以解决TomCat多虚拟站点的配置问题的,经过试验和参考官方网站资料,终于解决了这个问题.
  参考资料:Apache Tomcat文档http://tomcat.apache.org/tomcat-5.0-doc/config/host.html

  在文中有这么一段话:
  One or more Host elements are nested inside an Engine element. Inside the Host element, you can nest Context elements for the web applications associated with this virtual host. Exactly one of the Hosts associated with each Engine MUST have a name matching the defaultHost attribute of that Engine.

  译文:Engine元素中需要一个或多个Host元素,在Host元素里面,你必需有Context元素让网站应用程序与虚拟主机连接上,严密地说,每一个主机所关联的引擎必须有一个名字跟那个引擎默认的主机属性匹配 .
  可知,在Engine元素里面可以有多个Host,那么说,可以有在一个Engine里面设置多个服务器了,这正是我们需要的.每个Host元素里面要有一个Context元素.
  根据conf\server.xml里面的说明和范例,我样可以编写出下面一个配置文件:

  1TomCat 多虚拟站点配置<!-- Example Server Configuration File -->
  2TomCat 多虚拟站点配置<!-- Note that component elements are nested corresponding to their
  3TomCat 多虚拟站点配置     parent-child relationships with each other -->
  4TomCat 多虚拟站点配置
  5TomCat 多虚拟站点配置<!-- A "Server" is a singleton element that represents the entire JVM,
  6TomCat 多虚拟站点配置     which may contain one or more "Service" instances.  The Server
  7TomCat 多虚拟站点配置     listens for a shutdown command on the indicated port.
  8TomCat 多虚拟站点配置
  9TomCat 多虚拟站点配置     Note:  A "Server" is not itself a "Container", so you may not
 10TomCat 多虚拟站点配置     define subcomponents such as "Valves" or "Loggers" at this level.
 11TomCat 多虚拟站点配置 -->
 12TomCat 多虚拟站点配置
 13TomCat 多虚拟站点配置<Server port="8005" shutdown="SHUTDOWN">
 14TomCat 多虚拟站点配置
 15TomCat 多虚拟站点配置  <!-- Comment these entries out to disable JMX MBeans support used for the
 16TomCat 多虚拟站点配置       administration web application -->
 17TomCat 多虚拟站点配置  <Listener className="org.apache.catalina.core.AprLifecycleListener" />
 18TomCat 多虚拟站点配置  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
 19TomCat 多虚拟站点配置  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
 20TomCat 多虚拟站点配置  <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
 21TomCat 多虚拟站点配置
 22TomCat 多虚拟站点配置  <!-- Global JNDI resources -->
 23TomCat 多虚拟站点配置  <GlobalNamingResources>
 24TomCat 多虚拟站点配置
 25TomCat 多虚拟站点配置    <!-- Test entry for demonstration purposes -->
 26TomCat 多虚拟站点配置    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
 27TomCat 多虚拟站点配置
 28TomCat 多虚拟站点配置    <!-- Editable user database that can also be used by
 29TomCat 多虚拟站点配置         UserDatabaseRealm to authenticate users -->
 30TomCat 多虚拟站点配置    <Resource name="UserDatabase" auth="Container"
 31TomCat 多虚拟站点配置              type="org.apache.catalina.UserDatabase"
 32TomCat 多虚拟站点配置       description="User database that can be updated and saved"
 33TomCat 多虚拟站点配置           factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
 34TomCat 多虚拟站点配置          pathname="conf/tomcat-users.xml" />
 35TomCat 多虚拟站点配置
 36TomCat 多虚拟站点配置  </GlobalNamingResources>
 37TomCat 多虚拟站点配置
 38TomCat 多虚拟站点配置  <!-- A "Service" is a collection of one or more "Connectors" that share
 39TomCat 多虚拟站点配置       a single "Container" (and therefore the web applications visible
 40TomCat 多虚拟站点配置       within that Container).  Normally, that Container is an "Engine",
 41TomCat 多虚拟站点配置       but this is not required.
 42TomCat 多虚拟站点配置
 43TomCat 多虚拟站点配置       Note:  A "Service" is not itself a "Container", so you may not
 44TomCat 多虚拟站点配置       define subcomponents such as "Valves" or "Loggers" at this level.
 45TomCat 多虚拟站点配置   -->
 46TomCat 多虚拟站点配置
 47TomCat 多虚拟站点配置  <!-- Define the Tomcat Stand-Alone Service -->
 48TomCat 多虚拟站点配置  <Service name="Catalina">
 49TomCat 多虚拟站点配置
 50TomCat 多虚拟站点配置    <!-- A "Connector" represents an endpoint by which requests are received
 51TomCat 多虚拟站点配置         and responses are returned.  Each Connector passes requests on to the
 52TomCat 多虚拟站点配置         associated "Container" (normally an Engine) for processing.
 53TomCat 多虚拟站点配置
 54TomCat 多虚拟站点配置         By default, a non-SSL HTTP/1.1 Connector is established on port 8080.
 55TomCat 多虚拟站点配置         You can also enable an SSL HTTP/1.1 Connector on port 8443 by
 56TomCat 多虚拟站点配置         following the instructions below and uncommenting the second Connector
 57TomCat 多虚拟站点配置         entry.  SSL support requires the following steps (see the SSL Config
 58TomCat 多虚拟站点配置         HOWTO in the Tomcat 5 documentation bundle for more detailed
 59TomCat 多虚拟站点配置         instructions):
 60TomCat 多虚拟站点配置         * If your JDK version 1.3 or prior, download and install JSSE 1.0.2 or
 61TomCat 多虚拟站点配置           later, and put the JAR files into "$JAVA_HOME/jre/lib/ext".
 62TomCat 多虚拟站点配置         * Execute:
 63TomCat 多虚拟站点配置             %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows)
 64TomCat 多虚拟站点配置             $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA  (Unix)
 65TomCat 多虚拟站点配置           with a password value of "changeit" for both the certificate and
 66TomCat 多虚拟站点配置           the keystore itself.
 67TomCat 多虚拟站点配置
 68TomCat 多虚拟站点配置         By default, DNS lookups are enabled when a web application calls
 69TomCat 多虚拟站点配置         request.getRemoteHost().  This can have an adverse impact on
 70TomCat 多虚拟站点配置         performance, so you can disable it by setting the
 71TomCat 多虚拟站点配置         "enableLookups" attribute to "false".  When DNS lookups are disabled,
 72TomCat 多虚拟站点配置         request.getRemoteHost() will return the String version of the
 73TomCat 多虚拟站点配置         IP address of the remote client.
 74TomCat 多虚拟站点配置    -->
 75TomCat 多虚拟站点配置
 76TomCat 多虚拟站点配置    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
 77TomCat 多虚拟站点配置    <Connector
 78TomCat 多虚拟站点配置port="80"               maxHttpHeaderSize="8192"
 79TomCat 多虚拟站点配置               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
 80TomCat 多虚拟站点配置               enableLookups="false" redirectPort="8443" acceptCount="100"
 81TomCat 多虚拟站点配置               connectionTimeout="20000" disableUploadTimeout="true"  URIEncoding="GB2312"/>
 82TomCat 多虚拟站点配置    <!-- Note : To disable connection timeouts, set connectionTimeout value
 83TomCat 多虚拟站点配置     to 0 -->
 84TomCat 多虚拟站点配置
 85TomCat 多虚拟站点配置    <!-- Note : To use gzip compression you could set the following properties :
 86TomCat 多虚拟站点配置
 87TomCat 多虚拟站点配置               compression="on"
 88TomCat 多虚拟站点配置               compressionMinSize="2048"
 89TomCat 多虚拟站点配置               noCompressionUserAgents="gozilla, traviata"
 90TomCat 多虚拟站点配置               compressableMimeType="text/html,text/xml"
 91TomCat 多虚拟站点配置    -->
 92TomCat 多虚拟站点配置
 93TomCat 多虚拟站点配置    <!-- Define a SSL HTTP/1.1 Connector on port 8443 -->
 94TomCat 多虚拟站点配置    <!--
 95TomCat 多虚拟站点配置    <Connector port="8443" maxHttpHeaderSize="8192"
 96TomCat 多虚拟站点配置               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
 97TomCat 多虚拟站点配置               enableLookups="false" disableUploadTimeout="true"
 98TomCat 多虚拟站点配置               acceptCount="100" scheme="https" secure="true"
 99TomCat 多虚拟站点配置               clientAuth="false" sslProtocol="TLS" />
100TomCat 多虚拟站点配置    -->
101TomCat 多虚拟站点配置
102TomCat 多虚拟站点配置    <!-- Define an AJP 1.3 Connector on port 8009 -->
103TomCat 多虚拟站点配置    <Connector port="8009"
104TomCat 多虚拟站点配置               enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
105TomCat 多虚拟站点配置
106TomCat 多虚拟站点配置    <!-- Define a Proxied HTTP/1.1 Connector on port 8082 -->
107TomCat 多虚拟站点配置    <!-- See proxy documentation for more information about using this. -->
108TomCat 多虚拟站点配置    <!--
109TomCat 多虚拟站点配置    <Connector port="8082"
110TomCat 多虚拟站点配置               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
111TomCat 多虚拟站点配置               enableLookups="false" acceptCount="100" connectionTimeout="20000"
112TomCat 多虚拟站点配置               proxyPort="80" disableUploadTimeout="true" />
113TomCat 多虚拟站点配置    -->
114TomCat 多虚拟站点配置
115TomCat 多虚拟站点配置    <!-- An Engine represents the entry point (within Catalina) that processes
116TomCat 多虚拟站点配置         every request.  The Engine implementation for Tomcat stand alone
117TomCat 多虚拟站点配置         analyzes the HTTP headers included with the request, and passes them
118TomCat 多虚拟站点配置         on to the appropriate Host (virtual host). -->
119TomCat 多虚拟站点配置
120TomCat 多虚拟站点配置    <!-- You should set jvmRoute to support load-balancing via AJP ie :
121TomCat 多虚拟站点配置    <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
122TomCat 多虚拟站点配置    -->
123TomCat 多虚拟站点配置
124TomCat 多虚拟站点配置    <!-- Define the top level container in our container hierarchy -->
125TomCat 多虚拟站点配置    <Engine name="Catalina" defaultHost="ycoe.vicp.net">
126TomCat 多虚拟站点配置
127TomCat 多虚拟站点配置      <!-- The request dumper valve dumps useful debugging information about
128TomCat 多虚拟站点配置           the request headers and cookies that were received, and the response
129TomCat 多虚拟站点配置           headers and cookies that were sent, for all requests received by
130TomCat 多虚拟站点配置           this instance of Tomcat.  If you care only about requests to a
131TomCat 多虚拟站点配置           particular virtual host, or a particular application, nest this
132TomCat 多虚拟站点配置           element inside the corresponding <Host> or <Context> entry instead.
133TomCat 多虚拟站点配置
134TomCat 多虚拟站点配置           For a similar mechanism that is portable to all Servlet 2.4
135TomCat 多虚拟站点配置           containers, check out the "RequestDumperFilter" Filter in the
136TomCat 多虚拟站点配置           example application (the source for this filter may be found in
137TomCat 多虚拟站点配置           "$CATALINA_HOME/webapps/examples/WEB-INF/classes/filters").
138TomCat 多虚拟站点配置
139TomCat 多虚拟站点配置           Request dumping is disabled by default.  Uncomment the following
140TomCat 多虚拟站点配置           element to enable it. -->
141TomCat 多虚拟站点配置      <!--
142TomCat 多虚拟站点配置      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
143TomCat 多虚拟站点配置      -->
144TomCat 多虚拟站点配置
145TomCat 多虚拟站点配置      <!-- Because this Realm is here, an instance will be shared globally -->
146TomCat 多虚拟站点配置
147TomCat 多虚拟站点配置      <!-- This Realm uses the UserDatabase configured in the global JNDI
148TomCat 多虚拟站点配置           resources under the key "UserDatabase".  Any edits
149TomCat 多虚拟站点配置           that are performed against this UserDatabase are immediately
150TomCat 多虚拟站点配置           available for use by the Realm.  -->
151TomCat 多虚拟站点配置      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
152TomCat 多虚拟站点配置             resourceName="UserDatabase"/>
153TomCat 多虚拟站点配置
154TomCat 多虚拟站点配置      <!-- Comment out the old realm but leave here for now in case we
155TomCat 多虚拟站点配置           need to go back quickly -->
156TomCat 多虚拟站点配置      <!--
157TomCat 多虚拟站点配置      <Realm className="org.apache.catalina.realm.MemoryRealm" />
158TomCat 多虚拟站点配置      -->
159TomCat 多虚拟站点配置
160TomCat 多虚拟站点配置      <!-- Replace the above Realm with one of the following to get a Realm
161TomCat 多虚拟站点配置           stored in a database and accessed via JDBC -->
162TomCat 多虚拟站点配置
163TomCat 多虚拟站点配置      <!--
164TomCat 多虚拟站点配置      <Realm  className="org.apache.catalina.realm.JDBCRealm"
165TomCat 多虚拟站点配置             driverName="org.gjt.mm.mysql.Driver"
166TomCat 多虚拟站点配置          connectionURL="jdbc:mysql://localhost/authority"
167TomCat 多虚拟站点配置         connectionName="test" connectionPassword="test"
168TomCat 多虚拟站点配置              userTable="users" userNameCol="user_name" userCredCol="user_pass"
169TomCat 多虚拟站点配置          userRoleTable="user_roles" roleNameCol="role_name" />
170TomCat 多虚拟站点配置      -->
171TomCat 多虚拟站点配置
172TomCat 多虚拟站点配置      <!--
173TomCat 多虚拟站点配置      <Realm  className="org.apache.catalina.realm.JDBCRealm"
174TomCat 多虚拟站点配置             driverName="oracle.jdbc.driver.OracleDriver"
175TomCat 多虚拟站点配置          connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL"
176TomCat 多虚拟站点配置         connectionName="scott" connectionPassword="tiger"
177TomCat 多虚拟站点配置              userTable="users" userNameCol="user_name" userCredCol="user_pass"
178TomCat 多虚拟站点配置          userRoleTable="user_roles" roleNameCol="role_name" />
179TomCat 多虚拟站点配置      -->
180TomCat 多虚拟站点配置
181TomCat 多虚拟站点配置      <!--
182TomCat 多虚拟站点配置      <Realm  className="org.apache.catalina.realm.JDBCRealm"
183TomCat 多虚拟站点配置             driverName="sun.jdbc.odbc.JdbcOdbcDriver"
184TomCat 多虚拟站点配置          connectionURL="jdbc:odbc:CATALINA"
185TomCat 多虚拟站点配置              userTable="users" userNameCol="user_name" userCredCol="user_pass"
186TomCat 多虚拟站点配置          userRoleTable="user_roles" roleNameCol="role_name" />
187TomCat 多虚拟站点配置      -->
188TomCat 多虚拟站点配置
189TomCat 多虚拟站点配置      <!-- Define the default virtual host
190TomCat 多虚拟站点配置           Note: XML Schema validation will not work with Xerces 2.2.
191TomCat 多虚拟站点配置       -->
192TomCat 多虚拟站点配置      <Host name="ycoe.vicp.net" appBase="webapps"
193TomCat 多虚拟站点配置       unpackWARs="true" autoDeploy="true"
194TomCat 多虚拟站点配置       xmlValidation="false" xmlNamespaceAware="false">
195TomCat 多虚拟站点配置
196TomCat 多虚拟站点配置        <!-- Defines a cluster for this node,
197TomCat 多虚拟站点配置             By defining this element, means that every manager will be changed.
198TomCat 多虚拟站点配置             So when running a cluster, only make sure that you have webapps in there
199TomCat 多虚拟站点配置             that need to be clustered and remove the other ones.
200TomCat 多虚拟站点配置             A cluster has the following parameters:
201TomCat 多虚拟站点配置
202TomCat 多虚拟站点配置             className = the fully qualified name of the cluster class
203TomCat 多虚拟站点配置
204TomCat 多虚拟站点配置             name = a descriptive name for your cluster, can be anything
205TomCat 多虚拟站点配置
206TomCat 多虚拟站点配置             mcastAddr = the multicast address, has to be the same for all the nodes
207TomCat 多虚拟站点配置
208TomCat 多虚拟站点配置             mcastPort = the multicast port, has to be the same for all the nodes
209TomCat 多虚拟站点配置
210TomCat 多虚拟站点配置             mcastBindAddr = bind the multicast socket to a specific address
211TomCat 多虚拟站点配置
212TomCat 多虚拟站点配置             mcastTTL = the multicast TTL if you want to limit your broadcast
213TomCat 多虚拟站点配置
214TomCat 多虚拟站点配置             mcastSoTimeout = the multicast readtimeout
215TomCat 多虚拟站点配置
216TomCat 多虚拟站点配置             mcastFrequency = the number of milliseconds in between sending a "I'm alive" heartbeat
217TomCat 多虚拟站点配置
218TomCat 多虚拟站点配置             mcastDropTime = the number a milliseconds before a node is considered "dead" if no heartbeat is received
219TomCat 多虚拟站点配置
220TomCat 多虚拟站点配置             tcpThreadCount = the number of threads to handle incoming replication requests, optimal would be the same 
amount of threads as nodes
221TomCat 多虚拟站点配置
222TomCat 多虚拟站点配置             tcpListenAddress = the listen address (bind address) for TCP cluster request on this host,
223TomCat 多虚拟站点配置                                in case of multiple ethernet cards.
224TomCat 多虚拟站点配置                                auto means that address becomes
225TomCat 多虚拟站点配置                                InetAddress.getLocalHost().getHostAddress()
226TomCat 多虚拟站点配置
227TomCat 多虚拟站点配置             tcpListenPort = the tcp listen port
228TomCat 多虚拟站点配置
229TomCat 多虚拟站点配置             tcpSelectorTimeout = the timeout (ms) for the Selector.select() method in case the OS
230TomCat 多虚拟站点配置                                  has a wakup bug in java.nio. Set to 0 for no timeout
231TomCat 多虚拟站点配置
232TomCat 多虚拟站点配置             printToScreen = true means that managers will also print to std.out
233TomCat 多虚拟站点配置
234TomCat 多虚拟站点配置             expireSessionsOnShutdown = true means that
235TomCat 多虚拟站点配置
236TomCat 多虚拟站点配置             useDirtyFlag = true means that we only replicate a session after setAttribute,removeAttribute has been called.
237TomCat 多虚拟站点配置                            false means to replicate the session after each request.
238TomCat 多虚拟站点配置                            false means that replication would work for the following piece of code: (only for SimpleTcpReplicationManager)
239TomCat 多虚拟站点配置                            <%
240TomCat 多虚拟站点配置                            HashMap map = (HashMap)session.getAttribute("map");
241TomCat 多虚拟站点配置                            map.put("key","value");
242TomCat 多虚拟站点配置                            %>
243TomCat 多虚拟站点配置             replicationMode = can be either 'pooled', 'synchronous' or 'asynchronous'.
244TomCat 多虚拟站点配置                               * Pooled means that the replication happens using several sockets in a synchronous way. Ie, 
the data gets replicated, then the request return. This is the same as the 'synchronous' setting except it uses a pool of sockets, 
hence it is multithreaded. This is the fastest and safest configuration. To use this, also increase the nr of tcp threads 
that you have dealing with replication.
245TomCat 多虚拟站点配置                               * Synchronous means that the thread that executes the request, is also the
246TomCat 多虚拟站点配置                               thread the replicates the data to the other nodes, and will not return until all
247TomCat 多虚拟站点配置                               nodes have received the information.
248TomCat 多虚拟站点配置                               * Asynchronous means that there is a specific 'sender' thread for each cluster node,
249TomCat 多虚拟站点配置                               so the request thread will queue the replication request into a "smart" queue,
250TomCat 多虚拟站点配置                               and then return to the client.
251TomCat 多虚拟站点配置                               The "smart" queue is a queue where when a session is added to the queue, and the same session
252TomCat 多虚拟站点配置                               already exists in the queue from a previous request, that session will be replaced
253TomCat 多虚拟站点配置                               in the queue instead of replicating two requests. This almost never happens, unless there is a
254TomCat 多虚拟站点配置                               large network delay.
255TomCat 多虚拟站点配置        -->
256TomCat 多虚拟站点配置        <!--
257TomCat 多虚拟站点配置            When configuring for clustering, you also add in a valve to catch all the requests
258TomCat 多虚拟站点配置            coming in, at the end of the request, the session may or may not be replicated.
259TomCat 多虚拟站点配置            A session is replicated if and only if all the conditions are met:
260TomCat 多虚拟站点配置            1. useDirtyFlag is true or setAttribute or removeAttribute has been called AND
261TomCat 多虚拟站点配置            2. a session exists (has been created)
262TomCat 多虚拟站点配置            3. the request is not trapped by the "filter" attribute
263TomCat 多虚拟站点配置
264TomCat 多虚拟站点配置            The filter attribute is to filter out requests that could not modify the session,
265TomCat 多虚拟站点配置            hence we don't replicate the session after the end of this request.
266TomCat 多虚拟站点配置            The filter is negative, ie, anything you put in the filter, you mean to filter out,
267TomCat 多虚拟站点配置            ie, no replication will be done on requests that match one of the filters.
268TomCat 多虚拟站点配置            The filter attribute is delimited by ;, so you can't escape out ; even if you wanted to.
269TomCat 多虚拟站点配置
270TomCat 多虚拟站点配置            filter=".*\.gif;.*\.js;" means that we will not replicate the session after requests with the URI
271TomCat 多虚拟站点配置            ending with .gif and .js are intercepted.
272TomCat 多虚拟站点配置
273TomCat 多虚拟站点配置            The deployer element can be used to deploy apps cluster wide.
274TomCat 多虚拟站点配置            Currently the deployment only deploys/undeploys to working members in the cluster
275TomCat 多虚拟站点配置            so no WARs are copied upons startup of a broken node.
276TomCat 多虚拟站点配置            The deployer watches a directory (watchDir) for WAR files when watchEnabled="true"
277TomCat 多虚拟站点配置            When a new war file is added the war gets deployed to the local instance,
278TomCat 多虚拟站点配置            and then deployed to the other instances in the cluster.
279TomCat 多虚拟站点配置            When a war file is deleted from the watchDir the war is undeployed locally
280TomCat 多虚拟站点配置            and cluster wide
281TomCat 多虚拟站点配置        -->
282TomCat 多虚拟站点配置
283TomCat 多虚拟站点配置        <!--
284TomCat 多虚拟站点配置        <Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
285TomCat 多虚拟站点配置                 managerClassName="org.apache.catalina.cluster.session.DeltaManager"
286TomCat 多虚拟站点配置                 expireSessionsOnShutdown="false"
287TomCat 多虚拟站点配置                 useDirtyFlag="true"
288TomCat 多虚拟站点配置                 notifyListenersOnReplication="true">
289TomCat 多虚拟站点配置
290TomCat 多虚拟站点配置            <Membership
291TomCat 多虚拟站点配置                className="org.apache.catalina.cluster.mcast.McastService"
292TomCat 多虚拟站点配置                mcastAddr="228.0.0.4"
293TomCat 多虚拟站点配置                mcastPort="45564"
294TomCat 多虚拟站点配置                mcastFrequency="500"
295TomCat 多虚拟站点配置                mcastDropTime="3000"/>
296TomCat 多虚拟站点配置
297TomCat 多虚拟站点配置            <Receiver
298TomCat 多虚拟站点配置                className="org.apache.catalina.cluster.tcp.ReplicationListener"
299TomCat 多虚拟站点配置                tcpListenAddress="auto"
300TomCat 多虚拟站点配置                tcpListenPort="4001"
301TomCat 多虚拟站点配置                tcpSelectorTimeout="100"
302TomCat 多虚拟站点配置                tcpThreadCount="6"/>
303TomCat 多虚拟站点配置
304TomCat 多虚拟站点配置            <Sender
305TomCat 多虚拟站点配置                className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
306TomCat 多虚拟站点配置                replicationMode="pooled"
307TomCat 多虚拟站点配置                ackTimeout="15000"/>
308TomCat 多虚拟站点配置
309TomCat 多虚拟站点配置            <Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
310TomCat 多虚拟站点配置                   filter=".*\.gif;.*\.js;.*\.jpg;.*\.htm;.*\.html;.*\.txt;"/>
311TomCat 多虚拟站点配置
312TomCat 多虚拟站点配置            <Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
313TomCat 多虚拟站点配置                      tempDir="/tmp/war-temp/"
314TomCat 多虚拟站点配置                      deployDir="/tmp/war-deploy/"
315TomCat 多虚拟站点配置                      watchDir="/tmp/war-listen/"
316TomCat 多虚拟站点配置                      watchEnabled="false"/>
317TomCat 多虚拟站点配置        </Cluster>
318TomCat 多虚拟站点配置        -->
319TomCat 多虚拟站点配置
320TomCat 多虚拟站点配置
321TomCat 多虚拟站点配置
322TomCat 多虚拟站点配置        <!-- Normally, users must authenticate themselves to each web app
323TomCat 多虚拟站点配置             individually.  Uncomment the following entry if you would like
324TomCat 多虚拟站点配置             a user to be authenticated the first time they encounter a
325TomCat 多虚拟站点配置             resource protected by a security constraint, and then have that
326TomCat 多虚拟站点配置             user identity maintained across *all* web applications contained
327TomCat 多虚拟站点配置             in this virtual host. -->
328TomCat 多虚拟站点配置        <!--
329TomCat 多虚拟站点配置        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
330TomCat 多虚拟站点配置        -->
331TomCat 多虚拟站点配置
332TomCat 多虚拟站点配置        <!-- Access log processes all requests for this virtual host.  By
333TomCat 多虚拟站点配置             default, log files are created in the "logs" directory relative to
334TomCat 多虚拟站点配置             $CATALINA_HOME.  If you wish, you can specify a different
335TomCat 多虚拟站点配置             directory with the "directory" attribute.  Specify either a relative
336TomCat 多虚拟站点配置             (to $CATALINA_HOME) or absolute path to the desired directory.
337TomCat 多虚拟站点配置        -->
338TomCat 多虚拟站点配置        <!--
339TomCat 多虚拟站点配置        <Valve className="org.apache.catalina.valves.AccessLogValve"
340TomCat 多虚拟站点配置                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
341TomCat 多虚拟站点配置                 pattern="common" resolveHosts="false"/>
342TomCat 多虚拟站点配置        -->
343TomCat 多虚拟站点配置
344TomCat 多虚拟站点配置        <!-- Access log processes all requests for this virtual host.  By
345TomCat 多虚拟站点配置             default, log files are created in the "logs" directory relative to
346TomCat 多虚拟站点配置             $CATALINA_HOME.  If you wish, you can specify a different
347TomCat 多虚拟站点配置             directory with the "directory" attribute.  Specify either a relative
348TomCat 多虚拟站点配置             (to $CATALINA_HOME) or absolute path to the desired directory.
349TomCat 多虚拟站点配置             This access log implementation is optimized for maximum performance,
350TomCat 多虚拟站点配置             but is hardcoded to support only the "common" and "combined" patterns.
351TomCat 多虚拟站点配置        -->
352TomCat 多虚拟站点配置        <!--
353TomCat 多虚拟站点配置        <Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"
354TomCat 多虚拟站点配置                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
355TomCat 多虚拟站点配置                 pattern="common" resolveHosts="false"/>
356TomCat 多虚拟站点配置        -->
357TomCat 多虚拟站点配置    <Context docBase="D:\WORKS\EShop\EWebShop" path="/" reloadable="true" 
                workDir
="D:\WORKS\EShop\Tomcat\work\EWebShop">
358TomCat 多虚拟站点配置    </Context>
359TomCat 多虚拟站点配置      </Host>    
360TomCat 多虚拟站点配置<Host name="yvor.vicp.net" appBase="webapps"unpackWARs="true" autoDeploy="true"xmlValidation="false" 
                xmlNamespaceAware
="false">
361TomCat 多虚拟站点配置    <Context docBase="D:\WORKS\YCOE\ycoe" path="/" reloadable="true" workDir="D:\WORKS\YCOE\Tomcat\work\ycoe">
362TomCat 多虚拟站点配置    </Context>
363TomCat 多虚拟站点配置      </Host>
364TomCat 多虚拟站点配置    </Engine>
365TomCat 多虚拟站点配置  </Service>
366TomCat 多虚拟站点配置</Server>
367TomCat 多虚拟站点配置
368TomCat 多虚拟站点配置

  可以看到,这里修改了
  81行修改了两个参数值:<Connector port="80" maxHttpHeaderSize="8192"
 TomCat 多虚拟站点配置               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                enableLookups="false" redirectPort="8443" acceptCount="100"
                connectionTimeout="20000" disableUploadTimeout="true"  URIEncoding="GB2312"/>
          修改port是修改Tomcat的服务端口,默认为8080,URIEncoding改为GB2312是为了使用中文路径
    但不建议使用.

  125行:<Engine name="Catalina" defaultHost="ycoe.vicp.net">

        192行:<Host name="ycoe.vicp.net" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">

  然后再添加360行开始的<Host>元素:<Host name="yvor.vicp.net"  appBase="webapps" unpackWARs="true" autoDeploy="true"
        xmlValidation="false"  xmlNamespaceAware="false">
TomCat 多虚拟站点配置    <Context docBase="D:\WORKS\YCOE\ycoe"  path="/"  reloadable="true" 
            workDir
="D:\WORKS\YCOE\Tomcat\work\ycoe"></Context>
</Host>
  这里是设置我们的第二个虚拟网站的域名.
  注:<Context/>里面的内容并不是我们实际应用的,我们可以通过另一种比较方便而且容易修改的方式来设置这些参数.下面我们来做这方面的配置:
  1.在%CATALINA_HOME %\conf\Catalina目录下创建ycoe.vicp.net和yvor.vicp.net两个文件夹.
  2.在这两个文件夹里面创建ROOT.xml文件(要以ROOT.xml为名称,否则虽然不会出错,但不能用http://ycoe.vicp.nethttp://yvor.vicp.net直接访问)
  3.ROOT.xml的内容如下:
TomCat 多虚拟站点配置<?xml version='1.0' encoding='utf-8'?>
TomCat 多虚拟站点配置
<Context docBase="D:\WORKS\EShop\EWebShop" path="/" reloadable="true" 
workDir
="D:\WORKS\EShop\Tomcat\work\EWebShop">
TomCat 多虚拟站点配置
</Context>
TomCat 多虚拟站点配置

  根据自己的实际情况,设置这里的docBase 和workDir的路径.docBase是说明文档的路径,workDir是网站程序的路径,如果用相对路径,则是在%CATALINA_HOME %\webapp目录下,path是访问的路径

  参考官方文档:

  • Any XML file in the $CATALINA_HOME/conf/[engine_name]/[host_name] directory is assumed to contain a Context element (and its associated subelements) for a single web application. The docBase attribute of this <Context> element will typically be the absolute pathname to a web application directory, or the absolute pathname of a web application archive (WAR) file (which will not be expanded).
  • Any web application archive file within the application base (appBase) directory that does not have a corresponding directory of the same name (without the ".war" extension) will be automatically expanded, unless the unpackWARs property is set to false. If you redeploy an updated WAR file, be sure to delete the expanded directory when restarting Tomcat, so that the updated WAR file will be re-expanded (note that the auto deployer will automatically take care of this if it is enabled).
  • Any subdirectory within the application base directory that appears to be an unpacked web application (that is, it contains a /WEB-INF/web.xml file) will receive an automatically generated Context element, even if this directory is not mentioned in the conf/server.xml file. This generated Context entry will be configured according to the properties set in any DefaultContext element nested in this Host element. The context path for this deployed Context will be a slash character ("/") followed by the directory name, unless the directory name is ROOT, in which case the context path will be an empty string ("").

      你也可以在这两个目录下创建其它xml的文件

      但是这时你通过浏览器访问http://ycoe.vicp.nethttp://yvor.vicp.net时并不能浏览到你的网页,因为它把这些网址解析到广域网上去了,除非你用域名绑定.
      为了让局域本机不把这两个网址解析到广域网上去.我们可以通过以下设置实现(Windows XP,其它操作系统没有试过):
     1.用文本编辑器打开C:\WINDOWS\system32\drivers\etc目录的hosts文件
     2.在内容最后另起一行,添加以下内容:
                127.0.0.1       ycoe.vicp.net
                127.0.0.1       yvor.vicp.net

      可以由上面的注释部分了解它的作用:

    TomCat 多虚拟站点配置# Copyright (c) 1993-1999 Microsoft Corp.
    TomCat 多虚拟站点配置#
    TomCat 多虚拟站点配置# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    TomCat 多虚拟站点配置#
    TomCat 多虚拟站点配置# This file contains the mappings of IP addresses to host names. Each
    TomCat 多虚拟站点配置# entry should be kept on an individual line. The IP address should
    TomCat 多虚拟站点配置# be placed in the first column followed by the corresponding host name.
    TomCat 多虚拟站点配置# The IP address and the host name should be separated by at least one
    TomCat 多虚拟站点配置# space.
    TomCat 多虚拟站点配置#
    TomCat 多虚拟站点配置# Additionally, comments (such as these) may be inserted on individual
    TomCat 多虚拟站点配置# lines or following the machine name denoted by a '#' symbol.
    TomCat 多虚拟站点配置#
    TomCat 多虚拟站点配置# For example:
    TomCat 多虚拟站点配置#
    TomCat 多虚拟站点配置#      102.54.94.97     rhino.acme.com          # source server
    TomCat 多虚拟站点配置#       38.25.63.10     x.acme.com              # x client host

      到这里,全部的配置已经完成了.重启Tomcat,打开http://ycoe.vicp.nethttp://yvor.vicp.net就可以看到预期的效果了.呵呵

      下载相关文件https://files.cnblogs.com/ycoe/Catalina.rar

                        --原创文章,可以随意复制发表,但请注明出处与作者
                                       BY YCOE

  • 相关文章: