麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 網站 > Tomcat > 正文

TomCat 多虛擬站點配置

2024-09-06 19:01:06
字體:
來源:轉載
供稿:網友
中國最大的web開發資源網站及技術社區,
  在網絡上找了許久,沒有一個真正可以解決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里面的說明和范例,我樣可以編寫出下面一個配置文件:

  1<!-- example server configuration file -->
  2<!-- note that component elements are nested corresponding to their
  3     parent-child relationships with each other -->
  4
  5<!-- a "server" is a singleton element that represents the entire jvm,
  6     which may contain one or more "service" instances.  the server
  7     listens for a shutdown command on the indicated port.
  8
  9     note:  a "server" is not itself a "container", so you may not
 10     define subcomponents such as "valves" or "loggers" at this level.
 11 -->
 12
 13<server port="8005" shutdown="shutdown">
 14
 15  <!-- comment these entries out to disable jmx mbeans support used for the
 16       administration web application -->
 17  <listener classname="org.apache.catalina.core.aprlifecyclelistener" />
 18  <listener classname="org.apache.catalina.mbeans.serverlifecyclelistener" />
 19  <listener classname="org.apache.catalina.mbeans.globalresourceslifecyclelistener" />
 20  <listener classname="org.apache.catalina.storeconfig.storeconfiglifecyclelistener"/>
 21
 22  <!-- global jndi resources -->
 23  <globalnamingresources>
 24
 25    <!-- test entry for demonstration purposes -->
 26    <environment name="simplevalue" type="java.lang.integer" value="30"/>
 27
 28    <!-- editable user database that can also be used by
 29         userdatabaserealm to authenticate users -->
 30    <resource name="userdatabase" auth="container"
 31              type="org.apache.catalina.userdatabase"
 32       description="user database that can be updated and saved"
 33           factory="org.apache.catalina.users.memoryuserdatabasefactory"
 34          pathname="conf/tomcat-users.xml" />
 35
 36  </globalnamingresources>
 37
 38  <!-- a "service" is a collection of one or more "connectors" that share
 39       a single "container" (and therefore the web applications visible
 40       within that container).  normally, that container is an "engine",
 41       but this is not required.
 42
 43       note:  a "service" is not itself a "container", so you may not
 44       define subcomponents such as "valves" or "loggers" at this level.
 45   -->
 46
 47  <!-- define the tomcat stand-alone service -->
 48  <service name="catalina">
 49
 50    <!-- a "connector" represents an endpoint by which requests are received
 51         and responses are returned.  each connector passes requests on to the
 52         associated "container" (normally an engine) for processing.
 53
 54         by default, a non-ssl http/1.1 connector is established on port 8080.
 55         you can also enable an ssl http/1.1 connector on port 8443 by
 56         following the instructions below and uncommenting the second connector
 57         entry.  ssl support requires the following steps (see the ssl config
 58         howto in the tomcat 5 documentation bundle for more detailed
 59         instructions):
 60         * if your jdk version 1.3 or prior, download and install jsse 1.0.2 or
 61           later, and put the jar files into "$java_home/jre/lib/ext".
 62         * execute:
 63             %java_home%/bin/keytool -genkey -alias tomcat -keyalg rsa (windows)
 64             $java_home/bin/keytool -genkey -alias tomcat -keyalg rsa  (unix)
 65           with a password value of "changeit" for both the certificate and
 66           the keystore itself.
 67
 68         by default, dns lookups are enabled when a web application calls
 69         request.getremotehost().  this can have an adverse impact on
 70         performance, so you can disable it by setting the
 71         "enablelookups" attribute to "false".  when dns lookups are disabled,
 72         request.getremotehost() will return the string version of the
 73         ip address of the remote client.
 74    -->
 75
 76    <!-- define a non-ssl http/1.1 connector on port 8080 -->
 77    <connector
 78port="80"               maxhttpheadersize="8192"
 79               maxthreads="150" minsparethreads="25" maxsparethreads="75"
 80               enablelookups="false" redirectport="8443" acceptcount="100"
 81               connectiontimeout="20000" disableuploadtimeout="true"  uriencoding="gb2312"/>
 82    <!-- note : to disable connection timeouts, set connectiontimeout value
 83     to 0 -->
 84
 85    <!-- note : to use gzip compression you could set the following properties :
 86
 87               compression="on"
 88               compressionminsize="2048"
 89               nocompressionuseragents="gozilla, traviata"
 90               compressablemimetype="text/html,text/xml"
 91    -->
 92
 93    <!-- define a ssl http/1.1 connector on port 8443 -->
 94    <!--
 95    <connector port="8443" maxhttpheadersize="8192"
 96               maxthreads="150" minsparethreads="25" maxsparethreads="75"
 97               enablelookups="false" disableuploadtimeout="true"
 98               acceptcount="100" scheme="https" secure="true"
 99               clientauth="false" sslprotocol="tls" />
100    -->
101
102    <!-- define an ajp 1.3 connector on port 8009 -->
103    <connector port="8009"
104               enablelookups="false" redirectport="8443" protocol="ajp/1.3" />
105
106    <!-- define a proxied http/1.1 connector on port 8082 -->
107    <!-- see proxy documentation for more information about using this. -->
108    <!--
109    <connector port="8082"
110               maxthreads="150" minsparethreads="25" maxsparethreads="75"
111               enablelookups="false" acceptcount="100" connectiontimeout="20000"
112               proxyport="80" disableuploadtimeout="true" />
113    -->
114
115    <!-- an engine represents the entry point (within catalina) that processes
116         every request.  the engine implementation for tomcat stand alone
117         analyzes the http headers included with the request, and passes them
118         on to the appropriate host (virtual host). -->
119
120    <!-- you should set jvmroute to support load-balancing via ajp ie :
121    <engine name="standalone" defaulthost="localhost" jvmroute="jvm1">
122    -->
123
124    <!-- define the top level container in our container hierarchy -->
125    <engine name="catalina" defaulthost="ycoe.vicp.net">
126
127      <!-- the request dumper valve dumps useful debugging information about
128           the request headers and cookies that were received, and the response
129           headers and cookies that were sent, for all requests received by
130           this instance of tomcat.  if you care only about requests to a
131           particular virtual host, or a particular application, nest this
132           element inside the corresponding <host> or <context> entry instead.
133
134           for a similar mechanism that is portable to all servlet 2.4
135           containers, check out the "requestdumperfilter" filter in the
136           example application (the source for this filter may be found in
137           "$catalina_home/webapps/examples/web-inf/classes/filters").
138
139           request dumping is disabled by default.  uncomment the following
140           element to enable it. -->
141      <!--
142      <valve classname="org.apache.catalina.valves.requestdumpervalve"/>
143      -->
144
145      <!-- because this realm is here, an instance will be shared globally -->
146
147      <!-- this realm uses the userdatabase configured in the global jndi
148           resources under the key "userdatabase".  any edits
149           that are performed against this userdatabase are immediately
150           available for use by the realm.  -->
151      <realm classname="org.apache.catalina.realm.userdatabaserealm"
152             resourcename="userdatabase"/>
153
154      <!-- comment out the old realm but leave here for now in case we
155           need to go back quickly -->
156      <!--
157      <realm classname="org.apache.catalina.realm.memoryrealm" />
158      -->
159
160      <!-- replace the above realm with one of the following to get a realm
161           stored in a database and accessed via jdbc -->
162
163      <!--
164      <realm  classname="org.apache.catalina.realm.jdbcrealm"
165             drivername="org.gjt.mm.mysql.driver"
166          connectionurl="jdbc:mysql://localhost/authority"
167         connectionname="test" connectionpassword="test"
168              usertable="users" usernamecol="user_name" usercredcol="user_pass"
169          userroletable="user_roles" rolenamecol="role_name" />
170      -->
171
172      <!--
173      <realm  classname="org.apache.catalina.realm.jdbcrealm"
174             drivername="oracle.jdbc.driver.oracledriver"
175          connectionurl="jdbc:oracle:thin:@ntserver:1521:orcl"
176         connectionname="scott" connectionpassword="tiger"
177              usertable="users" usernamecol="user_name" usercredcol="user_pass"
178          userroletable="user_roles" rolenamecol="role_name" />
179      -->
180
181      <!--
182      <realm  classname="org.apache.catalina.realm.jdbcrealm"
183             drivername="sun.jdbc.odbc.jdbcodbcdriver"
184          connectionurl="jdbc:odbc:catalina"
185              usertable="users" usernamecol="user_name" usercredcol="user_pass"
186          userroletable="user_roles" rolenamecol="role_name" />
187      -->
188
189      <!-- define the default virtual host
190           note: xml schema validation will not work with xerces 2.2.
191       -->
192      <host name="ycoe.vicp.net" appbase="webapps"
193       unpackwars="true" autodeploy="true"
194       xmlvalidation="false" xmlnamespaceaware="false">
195
196        <!-- defines a cluster for this node,
197             by defining this element, means that every manager will be changed.
198             so when running a cluster, only make sure that you have webapps in there
199             that need to be clustered and remove the other ones.
200             a cluster has the following parameters:
201
202             classname = the fully qualified name of the cluster class
203
204             name = a descriptive name for your cluster, can be anything
205
206             mcastaddr = the multicast address, has to be the same for all the nodes
207
208             mcastport = the multicast port, has to be the same for all the nodes
209
210             mcastbindaddr = bind the multicast socket to a specific address
211
212             mcastttl = the multicast ttl if you want to limit your broadcast
213
214             mcastsotimeout = the multicast readtimeout
215
216             mcastfrequency = the number of milliseconds in between sending a "i'm alive" heartbeat
217
218             mcastdroptime = the number a milliseconds before a node is considered "dead" if no heartbeat is received
219
220             tcpthreadcount = the number of threads to handle incoming replication requests, optimal would be the same 
amount of threads as nodes
221
222             tcplistenaddress = the listen address (bind address) for tcp cluster request on this host,
223                                in case of multiple ethernet cards.
224                                auto means that address becomes
225                                inetaddress.getlocalhost().gethostaddress()
226
227             tcplistenport = the tcp listen port
228
229             tcpselectortimeout = the timeout (ms) for the selector.select() method in case the os
230                                  has a wakup bug in java.nio. set to 0 for no timeout
231
232             printtoscreen = true means that managers will also print to std.out
233
234             expiresessionsonshutdown = true means that
235
236             usedirtyflag = true means that we only replicate a session after setattribute,removeattribute has been called.
237                            false means to replicate the session after each request.
238                            false means that replication would work for the following piece of code: (only for simpletcpreplicationmanager)
239                            <%
240                            hashmap map = (hashmap)session.getattribute("map");
241                            map.put("key","value");
242                            %>
243             replicationmode = can be either 'pooled', 'synchronous' or 'asynchronous'.
244                               * 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.
245                               * synchronous means that the thread that executes the request, is also the
246                               thread the replicates the data to the other nodes, and will not return until all
247                               nodes have received the information.
248                               * asynchronous means that there is a specific 'sender' thread for each cluster node,
249                               so the request thread will queue the replication request into a "smart" queue,
250                               and then return to the client.
251                               the "smart" queue is a queue where when a session is added to the queue, and the same session
252                               already exists in the queue from a previous request, that session will be replaced
253                               in the queue instead of replicating two requests. this almost never happens, unless there is a
254                               large network delay.
255        -->
256        <!--
257            when configuring for clustering, you also add in a valve to catch all the requests
258            coming in, at the end of the request, the session may or may not be replicated.
259            a session is replicated if and only if all the conditions are met:
260            1. usedirtyflag is true or setattribute or removeattribute has been called and
261            2. a session exists (has been created)
262            3. the request is not trapped by the "filter" attribute
263
264            the filter attribute is to filter out requests that could not modify the session,
265            hence we don't replicate the session after the end of this request.
266            the filter is negative, ie, anything you put in the filter, you mean to filter out,
267            ie, no replication will be done on requests that match one of the filters.
268            the filter attribute is delimited by ;, so you can't escape out ; even if you wanted to.
269
270            filter=".*/.gif;.*/.js;" means that we will not replicate the session after requests with the uri
271            ending with .gif and .js are intercepted.
272
273            the deployer element can be used to deploy apps cluster wide.
274            currently the deployment only deploys/undeploys to working members in the cluster
275            so no wars are copied upons startup of a broken node.
276            the deployer watches a directory (watchdir) for war files when watchenabled="true"
277            when a new war file is added the war gets deployed to the local instance,
278            and then deployed to the other instances in the cluster.
279            when a war file is deleted from the watchdir the war is undeployed locally
280            and cluster wide
281        -->
282
283        <!--
284        <cluster classname="org.apache.catalina.cluster.tcp.simpletcpcluster"
285                 managerclassname="org.apache.catalina.cluster.session.deltamanager"
286                 expiresessionsonshutdown="false"
287                 usedirtyflag="true"
288                 notifylistenersonreplication="true">
289
290            <membership
291                classname="org.apache.catalina.cluster.mcast.mcastservice"
292                mcastaddr="228.0.0.4"
293                mcastport="45564"
294                mcastfrequency="500"
295                mcastdroptime="3000"/>
296
297            <receiver
298                classname="org.apache.catalina.cluster.tcp.replicationlistener"
299                tcplistenaddress="auto"
300                tcplistenport="4001"
301                tcpselectortimeout="100"
302                tcpthreadcount="6"/>
303
304            <sender
305                classname="org.apache.catalina.cluster.tcp.replicationtransmitter"
306                replicationmode="pooled"
307                acktimeout="15000"/>
308
309            <valve classname="org.apache.catalina.cluster.tcp.replicationvalve"
310                   filter=".*/.gif;.*/.js;.*/.jpg;.*/.htm;.*/.html;.*/.txt;"/>
311
312            <deployer classname="org.apache.catalina.cluster.deploy.farmwardeployer"
313                      tempdir="/tmp/war-temp/"
314                      deploydir="/tmp/war-deploy/"
315                      watchdir="/tmp/war-listen/"
316                      watchenabled="false"/>
317        </cluster>
318        -->
319
320
321
322        <!-- normally, users must authenticate themselves to each web app
323             individually.  uncomment the following entry if you would like
324             a user to be authenticated the first time they encounter a
325             resource protected by a security constraint, and then have that
326             user identity maintained across *all* web applications contained
327             in this virtual host. -->
328        <!--
329        <valve classname="org.apache.catalina.authenticator.singlesignon" />
330        -->
331
332        <!-- access log processes all requests for this virtual host.  by
333             default, log files are created in the "logs" directory relative to
334             $catalina_home.  if you wish, you can specify a different
335             directory with the "directory" attribute.  specify either a relative
336             (to $catalina_home) or absolute path to the desired directory.
337        -->
338        <!--
339        <valve classname="org.apache.catalina.valves.accesslogvalve"
340                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
341                 pattern="common" resolvehosts="false"/>
342        -->
343
344        <!-- access log processes all requests for this virtual host.  by
345             default, log files are created in the "logs" directory relative to
346             $catalina_home.  if you wish, you can specify a different
347             directory with the "directory" attribute.  specify either a relative
348             (to $catalina_home) or absolute path to the desired directory.
349             this access log implementation is optimized for maximum performance,
350             but is hardcoded to support only the "common" and "combined" patterns.
351        -->
352        <!--
353        <valve classname="org.apache.catalina.valves.fastcommonaccesslogvalve"
354                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
355                 pattern="common" resolvehosts="false"/>
356        -->
357    <context docbase="d:/works/eshop/ewebshop" path="/" reloadable="true" 
                workdir="d:/works/eshop/tomcat/work/ewebshop">
358    </context>
359      </host>    
360<host name="yvor.vicp.net" appbase="webapps"unpackwars="true" autodeploy="true"xmlvalidation="false" 
                xmlnamespaceaware="false">
361    <context docbase="d:/works/ycoe/ycoe" path="/" reloadable="true" workdir="d:/works/ycoe/tomcat/work/ycoe">
362    </context>
363      </host>
364    </engine>
365  </service>
366</server>
367
368
  可以看到,這里修改了
  81行修改了兩個參數值:<connector port="80" maxhttpheadersize="8192"
                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">
    <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.net或http://yvor.vicp.net直接訪問)
  3.root.xml的內容如下:
<?xml version='1.0' encoding='utf-8'?>
<context docbase="d:/works/eshop/ewebshop" path="/" reloadable="true" 
workdir="d:/works/eshop/tomcat/work/ewebshop">
</context>

  根據自己的實際情況,設置這里的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.net或http://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

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


# copyright (c) 1993-1999 microsoft corp.
#
# this is a sample hosts file used by microsoft tcp/ip for windows.
#
# this file contains the mappings of ip addresses to host names. each
# entry should be kept on an individual line. the ip address should
# be placed in the first column followed by the corresponding host name.
# the ip address and the host name should be separated by at least one
# space.
#
# additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# for example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host
  到這里,全部的配置已經完成了.重啟tomcat,打開http://ycoe.vicp.net或http://yvor.vicp.net就可以看到預期的效果了.呵呵 
  下載相關文件http://www.cnblogs.com/files/ycoe/catalina.rar
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亚洲无限资源 | 国产一区二区欧美 | 亚洲精品无码不卡在线播放he | 国产精品久久久久久久久久久久午夜 | 国产精品成人久久久久a级 欧美特黄一级高清免费的香蕉 | 亚洲第一页夜 | 欧美日韩免费看 | 极品国产91在线网站 | 久久国产一级 | 99爱视频在线 | 国产精品99精品 | 久久美女免费视频 | 激情小说另类 | 精品国产一区二区三区久久久蜜月 | 伊人午夜 | 把娇妻调教成暴露狂 | 神马久久蜜桃 | 久久综合一区 | 日本网站在线看 | 中文字幕电影免费播放 | 8x成人在线电影 | 日韩黄色av网站 | 亚洲成人激情av | 免费黄网站在线播放 | 色中色激情影院 | 黄色免费高清网站 | 国产日韩线路一线路二 | 国产成人77亚洲精品www | 性爱网站| 精品国产一区二区三区成人影院 | 免看黄大片aa | 久久精品欧美一区 | 国产一级一国产一级毛片 | 成人资源在线 | 成人片免费视频 | 日韩黄色片在线观看 | 污片在线观看视频 | av91肉丝一区二区电影 | 国产精品久久久久久模特 | 国产伦久视频免费观看视频 | 污片在线观看视频 |