您的位置:首页 > 运维架构 > Tomcat

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
foobar
context as a war file in the
ren
host, use
$CATALINA_HOME/renapps/foobar.war
. Note that the default or ROOT context for
ren
would 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-INF
directory and then place your Context definition in it in a file named
context.xml
. i.e.
$CATALINA_HOME/renapps/ROOT/META-INF/context.xml
This 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标签的说明:

AttributeDescription
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.Engine
interface. 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
name
attributes 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.

tomcat 官方对Host标签的说明:

AttributeDescription
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_BASE
directory. 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
appBase
directory 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.Host
interface. 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
defaultHost
setting for that Engine. See Host Name Aliases for information on how to assign more than one network name to the same virtual host.

最后,便可以通过http://localhost/进行访问了.

如果要添加其它应用,则将应用部署在appBase指定的目录,记得在应用的META-INF目录中添加"应用名.xml"就可以了.

当然,如:faceye.xml.那么,将来的访问就为:http://localhost/faceye.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: