TomCat 多虚拟站点配置
在网络上找了许久,没有一个真正可以解决TomCat多虚拟站点的配置问题的,经过试验和参考官方网站资料,终于解决了这个问题.
参考资料:Apache Tomcat文档/UpLoadFiles/NewsPhoto/\.js;.*\.jpg;.*\.htm;.*\.html;.*\.txt;"/>
311
312313 tempDir="/tmp/war-temp/"
314 deployDir="/tmp/war-deploy/"
315 watchDir="/tmp/war-listen/"
316 watchEnabled="false"/>
317
318 -->
319
320
321
322
328
331
332
338
343
344
352
357 workDir="D:\WORKS\EShop\Tomcat\work\EWebShop">
358
359
360 xmlNamespaceAware="false">
361
362
363
364
365
366
367
368
可以看到,这里修改了
81行修改了两个参数值: maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GB2312"/>
修改port是修改Tomcat的服务端口,默认为8080,URIEncoding改为GB2312是为了使用中文路径
但不建议使用.
125行:
192行:
然后再添加360行开始的元素: xmlValidation="false" xmlNamespaceAware="false">
workDir="D:\WORKS\YCOE\Tomcat\work\ycoe">
这里是设置我们的第二个虚拟网站的 域名.
注: 里面的内容并不是我们实际应用的,我们可以通过另一种比较方便而且容易修改的方式来设置这些参数.下面我们来做这方面的配置:
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的内容如下:
workDir="D:\WORKS\EShop\Tomcat\work\EWebShop">
根据自己的实际情况,设置这里的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 thiselement 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://netadmin.77169.com/HTML/20060429003011.html
参考资料:Apache Tomcat文档/UpLoadFiles/NewsPhoto/\.js;.*\.jpg;.*\.htm;.*\.html;.*\.txt;"/>
311
312
314 deployDir="/tmp/war-deploy/"
315 watchDir="/tmp/war-listen/"
316 watchEnabled="false"/>
317
318 -->
319
320
321
322
328
331
332
338
343
344
352
357
358
359
360
361
362
363
364
365
366
367
368
可以看到,这里修改了
81行修改了两个参数值:
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GB2312"/>
修改port是修改Tomcat的服务端口,默认为8080,URIEncoding改为GB2312是为了使用中文路径
但不建议使用.
125行:
192行:
然后再添加360行开始的
这里是设置我们的第二个虚拟网站的
注:
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的内容如下:
根据自己的实际情况,设置这里的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
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://netadmin.77169.com/HTML/20060429003011.html
0
相关文章