Tomcat 5.5 server.xml 配置的一些问题

Posted on 2008-05-07 13:02 xan 阅读(1340) 评论(0)  编辑  收藏 所属分类: Java
  • Host Name:
Network name of this virtual host, as registered in your Domain Name Service server.
Exactly one of the Hosts associated with each Engine MUST have a name matching the defaultHost attribute of that Engine.

  • Host Name Alias:
in some circumstances, it is desireable that two or more network names should resolve to the same virtual host.
<Host name="www.mycompany.com" ...>
    ...
    <Alias>mycompany.com</Alias>
    ...
</Host>
In order for this strategy to be effective, all of the network names involved must be registered
  • host 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.
appBase="webapps" is the default value.

  • host context:
You can nest one or more Context elements inside this Host element, each representing a different web application associated with this virtual host.

  • context docBase:
The Document Base (also known as the Context Root) directory for this web application, or the pathname to the web application archive file (if this web application is being executed directly from the WAR file). You may specify an absolute pathname for this directory or WAR file, or a pathname that is relative to the appBase directory of the owning Host.
If a symbolic link is used for docBase then changes to the symbolic link will only be effective after a Tomcat restart or by undeploying and redeploying the conext. A context reload is not sufficient.
Do not choose a docBase that starts with your Host's appBase string. The default appBase is "webapps" so do not choose a docBase like "webapps-foo." Doing so will lead to deployment errors: see Bugzilla for details.
The value of this field must not be set when the Context is configured using a META-INF/context.xml file as it will be inferred by the automatic deployment process.

  • context path:
The context path of this web application, which is matched against the beginning of each request URI to select the appropriate web application for processing.
All of the context paths within a particular Host must be unique. If you specify a context path of an empty string (""), you are defining the default web application for this Host, which will process all requests not assigned to other Contexts.


问题: 为什么我可以使用http://www.mysite.com:8080/ 去访问Test Project,  而使用
http://localhost:8080/ 却不能,需使用http://localhost:8080/Test_Project访问

C:\WINDOWS\system32\drivers\etc\hosts
127.0.0.1       localhost
127.0.0.1        www.mysite.com

这个问题是“直接使用
http://localhost 或 http://www.mysite.com/ 访问开发的项目, 为了达到这一目的,有以下途径:
途径1:
    设置 context path=“” ,如
<Context docBase="Test Project" path="" reloadable="true" crossContext="true" source="org.eclipse.jst.j2ee.server:Test Project"/></Host>
但是这有一个问题
使用eclipse servers 新建一个server,产生配置文件
D:\WorkSpace\MY_DEV\Servers\Tomcat v5.5 Server @localhost-config\server.xml, 修改该自动生成的文件
启动server后,这些配置文件将被发布到tomcat webapps的同级目录conf下,而且在发布时server.xml的内容为eclipse自动生成的内容用户的修改被抛弃。所以为了达到
“直接使用http://localhost 或 http://www.mysite.com/ 访问开发的项目这一目标,有两种方法:
方法一:
    直接修改tomcat conf目录下的server.xml文件。

方法二:
    在eclipse中,在自动生成的server.xml基础上添加一个host
    <Host appBase="webapps" autoDeploy="true" name="www.mysite.com" unpackWARs="true">
        <Context docBase="Test Project" path="" reloadable="true" source="org.eclipse.jst.j2ee.server:
Test Project"/>
    </Host>
该修改在"关闭,再启动"(直接重启不行)server后,能被更新到tomcat conf下面的server.xml
在项目发布中,最终生效的是tomcat conf下的server.xml


途径2:来自
http://blog.csdn.net/miqi770/archive/2008/02/20/2109805.aspx,未尝试

使用eclipse发布xm到tomcat
 把ROOT目录删掉,把xm重命名ROOT
 使用http://localhost时,可以直接访问自己开发的项目



只有注册用户登录后才能发表评论。


网站导航:
 

posts - 36, comments - 2, trackbacks - 0, articles - 0

Copyright © xan