Tomcat6下配置新的虚拟主机-波折一二三
2008-12-03 21:30
399 查看
一直使用tomcat5,今天换用了tomcat6,没想到,tomcat6的虚拟主机配置,与tomcat5的有很多不同.
在tomcat5下,经过配置,我一直使用http://localhost/来进行日常的开发调试工作.
换了tomcat6,想当然的在context.xml的host标签中加入context标记,没想到,
Tomcat6不认了,于是乎,去官方看文档,在官方有文档中,有这样的描述 :
Contexts are normally located underneath the appBase directory. For example, to deploy the
意思也就是说,如果要配置成直接使用http://localhost/的方式进行访问,
要将war包命名为ROOT,同时根据文档:
Within your Context, create a
这样也就是说,在WEB-INF/META-INF下面,需要添加一个context.xml文件,这样做的主要目的一方面,是希望单独web应用的修改,不用重启tomcat服务器,就可以将新配置的修改 重新加载,另一方面,当然是希望各个应用的配置可以相互,隔离.
整个tomcat配置虚拟主机的官方文档在这里可以找到.
http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html
经过反复尝试,最终得如下步骤:
1:修改/tomcat6/conf/server.xml
主要修改为:
<Engine name="Catalina" defaultHost="localhost">
这里的defaultHost 要与下面的 hostname 保持一致
name要与接下来创建的目录名一致
<Host name="localhost" appBase="F:"WebDeploy"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
其中,appBase指定了虚拟目录所在位置.
2.在/tomcat6/conf/下创建与"Engine"标签name属于指定值一致的目录名
比如我使用的是Catalina,那么就创建名为Catalina的目录,其下创建名为localhost(与Host标签的name属性一致)的目录 .
3.在我们的应用下,在目录META-INF添加ROOT.xml,内容为:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="" docBase="ROOT" debug="0" reloadable="true"></Context>
整个配置完成,重启服务器.
tomcat官方对Engine标签的说明:
tomcat 官方对Host标签的说明:
最后,便可以通过http://localhost/进行访问了.
如果要添加其它应用,则将应用部署在appBase指定的目录,记得在应用的META-INF目录中添加"应用名.xml"就可以了.
当然,如:faceye.xml.那么,将来的访问就为:http://localhost/faceye.
在tomcat5下,经过配置,我一直使用http://localhost/来进行日常的开发调试工作.
换了tomcat6,想当然的在context.xml的host标签中加入context标记,没想到,
Tomcat6不认了,于是乎,去官方看文档,在官方有文档中,有这样的描述 :
Contexts are normally located underneath the appBase directory. For example, to deploy the
foobarcontext as a war file in the
renhost, use
$CATALINA_HOME/renapps/foobar.war. Note that the default or ROOT context for
renwould be deployed as
$CATALINA_HOME/renapps/ROOT.war(WAR) or
$CATALINA_HOME/renapps/ROOR(directory).
意思也就是说,如果要配置成直接使用http://localhost/的方式进行访问,
要将war包命名为ROOT,同时根据文档:
Within your Context, create a
META-INFdirectory and then place your Context definition in it in a file named
context.xml. i.e.
$CATALINA_HOME/renapps/ROOT/META-INF/context.xmlThis makes deployment easier, particularly if you're distributing a WAR file.
这样也就是说,在WEB-INF/META-INF下面,需要添加一个context.xml文件,这样做的主要目的一方面,是希望单独web应用的修改,不用重启tomcat服务器,就可以将新配置的修改 重新加载,另一方面,当然是希望各个应用的配置可以相互,隔离.
整个tomcat配置虚拟主机的官方文档在这里可以找到.
http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html
经过反复尝试,最终得如下步骤:
1:修改/tomcat6/conf/server.xml
主要修改为:
<Engine name="Catalina" defaultHost="localhost">
这里的defaultHost 要与下面的 hostname 保持一致
name要与接下来创建的目录名一致
<Host name="localhost" appBase="F:"WebDeploy"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
其中,appBase指定了虚拟目录所在位置.
2.在/tomcat6/conf/下创建与"Engine"标签name属于指定值一致的目录名
比如我使用的是Catalina,那么就创建名为Catalina的目录,其下创建名为localhost(与Host标签的name属性一致)的目录 .
3.在我们的应用下,在目录META-INF添加ROOT.xml,内容为:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="" docBase="ROOT" debug="0" reloadable="true"></Context>
整个配置完成,重启服务器.
tomcat官方对Engine标签的说明:
Attribute | Description |
---|---|
backgroundProcessorDelay | This value represents the delay in seconds between the invocation of the backgroundProcess method on this engine and its child containers, including all hosts and contexts. Child containers will not be invoked if their delay value is not negative (which would mean they are using their own processing thread). Setting this to a positive value will cause a thread to be spawn. After waiting the specified amount of time, the thread will invoke the backgroundProcess method on this engine and all its child containers. If not specified, the default value for this attribute is 10, which represent a 10 seconds delay. |
className | Java class name of the implementation to use. This class must implement the org.apache.catalina.Engineinterface. If not specified, the standard value (defined below) will be used. |
defaultHost | The default host name, which identifies the Host that will process requests directed to host names on this server, but which are not configured in this configuration file. This name MUST match the nameattributes of one of the Host elements nested immediately inside. |
jvmRoute | Identifier which must be used in load balancing scenarios to enable session affinity. The identifier, which must be unique across all Tomcat 6 servers which participate in the cluster, will be appended to the generated session identifier, therefore allowing the front end proxy to always forward a particular session to the same Tomcat 6 instance. |
name | Logical name of this Engine, used in log and error messages. When using muliple Service elements in the same Server, each Engine MUST be assigned a unique name. |
Attribute | Description |
---|---|
appBase | The Application Base directory for this virtual host. This is the pathname of a directory that may contain web applications to be deployed on this virtual host. You may specify an absolute pathname for this directory, or a pathname that is relative to the $CATALINA_BASEdirectory. See Automatic Application Deployment for more information on automatic recognition and deployment of web applications to be deployed automatically. |
autoDeploy | This flag value indicates if new web applications, dropped in to the appBasedirectory while Tomcat is running, should be automatically deployed. The flag's value defaults to true. See Automatic Application Deployment for more information. |
backgroundProcessorDelay | This value represents the delay in seconds between the invocation of the backgroundProcess method on this host and its child containers, including all contexts. Child containers will not be invoked if their delay value is not negative (which would mean they are using their own processing thread). Setting this to a positive value will cause a thread to be spawn. After waiting the specified amount of time, the thread will invoke the backgroundProcess method on this host and all its child containers. A host will use background processing to perform live web application deployment related tasks. If not specified, the default value for this attribute is -1, which means the host will rely on the background processing thread of its parent engine. |
className | Java class name of the implementation to use. This class must implement the org.apache.catalina.Hostinterface. If not specified, the standard value (defined below) will be used. |
deployOnStartup | This flag value indicates if web applications from this host should be automatically deployed by the host configurator. The flag's value defaults to true. See Automatic Application Deployment for more information. |
name | Network name of this virtual host, as registered in your Domain Name Service server. One of the Hosts nested within an Engine MUST have a name that matches the defaultHostsetting for that Engine. See Host Name Aliases for information on how to assign more than one network name to the same virtual host. |
如果要添加其它应用,则将应用部署在appBase指定的目录,记得在应用的META-INF目录中添加"应用名.xml"就可以了.
当然,如:faceye.xml.那么,将来的访问就为:http://localhost/faceye.
相关文章推荐
- tomcat配置虚拟主机
- IIS + Tomcat虚拟主机的配置
- Tomcat 5.5 如何配置多个虚拟主机
- Tomcat虚拟主机配置方案(域名解析)For Windows/Linux(最完全版)
- Apache + JK + Tomcat + 虚拟主机 架构的整合配置方式
- Tomcat配置多个虚拟主机
- Apache2.2.x+tomcat单IP多域名多站点的虚拟主机配置详解(win2003环境)
- 16.4 配置Tomcat监听80端口 16.5/16.6/16.7 配置Tomcat虚拟主机16.8 Tomcat日志
- 配置Tomcat监听80端口、配置Tomcat虚拟主机、Tomcat日志
- day61:配置Tomcat虚拟主机及日记
- 关于TOMCat虚拟主机配置后工程启动几次的问题
- 配置Tomcat虚拟主机
- Tomcat的虚拟主机的配置
- Tomcat(tomcat虚拟主机,Tomcat日志,单机多实例配置实战,JVM设置和连接数设置)
- 关于tomcat配置虚拟主机
- 在tomcat中配置虚拟主机
- Tomcat中配置虚拟主机
- Tomcat配置虚拟主机 20111012
- 在Tomcat中配置虚拟主机
- Tomcat 6 配置虚拟主机<域名/二级域名>,并通过Tomcat控制台对多个Host进行管理