`

配置 Tomcat 的网站根目录、虚拟目录、端口等

阅读更多

你的 tomcat 目录中有一个 conf 目录,里头有一个 server.xml 文件,这就是相关的配置文件,搜索,你会找到有如下一句话

<Context path="" docBase="" debug="0"/>

这句话是被 <!-- 和 --> 包括起来注释掉的
先把注释去掉,然后在 docBase 中设置上你的网站根目录,哪下是我的那一段配置文件,其中的中文是为了说明写注释:

        <!-- Tomcat Root Context -->
        <!-- path 表示在浏览器里的目录,空表示根目录, docBase 表示在硬盘上所在的目录 -->
        <Context path="" docBase="h:\wwwroot\tomcat" debug="0"/>
        <!-- http://localhost:8080/tomcat_docs 所指向的硬盘目录, 这是是 tomcat 的一些文档 -->
        <Context path="/tomcat_docs" docBase="e:\tomcat\webapps\tomcat-docs" debug="0"/>
        <!-- Tomcat Manager Context -->
        <!-- 下面两项是对原来的进行修改以适应根目录的变化的, 即打开上述注释 -->
        <Context path="/manager" docBase="e:\tomcat\webapps\manager"
         debug="0" privileged="true"/>

        <!-- Tomcat Examples Context -->
        <Context path="/examples" docBase="e:\tomcat\webapps\examples" debug="0"
                 reloadable="true" crossContext="true">

注意:这时候端口是默认的 8080,需要使用 http://localhost:8080/ 才能访问
要改端口需要找到

    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector className="org.apache.catalina.connector.http.HttpConnector"
               port="8080" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" connectionTimeout="60000"/>

将端口 port 设置为 80, 改后如下

    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector className="org.apache.catalina.connector.http.HttpConnector"
               port="80" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" connectionTimeout="60000"/>

修改保存后,要重启TOMCAT,
注意,此时要停止IIS,否则端口会发生冲突。 上面是网站根目录\端口的配置

下面看看Jsp、TOMCAT虚拟目录的设置

在Tomcat的配置文件server.xml中(server.xml一般在conf目录下面),

有这样几个标签:

<Host name="localhost"....
    <Context path="/love" docBase="x:\java\love" debug="0" reloadable="true" crossContext="true">

    其中,Host标记是用来配置虚拟主机的,就是可以多个域名指向一个tomcat,格式只要参考默认的就

可以了。

<context>是Host标记的子元素吧,表示一个虚拟目录,它主要有两个属性,path就相当于虚拟目录名字,

而 docbase则是具体的文件位置。在这里我的虚拟路径名称为love,实际上我的程序也就是html、jsp、

servlet都 放在了x:\java\love这个目录下了。 修改保存后,请重启TOMCAT

          这样我就可以通过 http://localhost/love/ 访问我的这个虚拟目录了。

不当错漏之处欢迎跟贴指正。本文适用于win2000下TOMCAT和JSP的配置。

 

 

来自:http://hi.baidu.com/xlnan/blog/item/3ed9e289cc8d23b90f24449f.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics