 |
TomCat 多虚拟站点配置 |
|
|
| TomCat 多虚拟站点配置 |
|
| 作者:佚名 文章来源:不详 点击数: 更新时间:2007-1-25 12:04:35 |
|
在网络上找了许久,没有一个真正可以解决TomCat多虚拟站点的配置问题的,经过试验和参考官方网站资料,终于解决了这个问题. 参考资料:Apache Tomcat文档/UpLoadFiles/NewsPhoto//.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.21safe.com】
|
|
| 文章录入:admin 责任编辑:admin |
|
|
上一篇文章: HtmlEncode过滤变量不足分析报 下一篇文章: 溢出原理 |
|
|
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |
|
|
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!) |
|
|
|
|
|