`

Tomcat 虚拟主机 虚拟目录

阅读更多

把一个外部的目录映射成能供tomcat访问的虚拟目录

 

打开tomcat的安装路径--conf下面找到server.xml 找到<host >标签

host标签中添加<Context path="/my" docBase="c:/myVerturalList"/>

/my 是供外部访问的虚拟目录,docBase是磁盘上面的真是文件夹,即存放供外部访问的资源文件夹

 <Context path=" " docBase="c:/myVerturalList"/> 如果path为空 可以配置成缺省的web应用

 

 

这种配置的缺点:每次配置后  服务器都要重启之后才能生效

其他配置方法  产看tomcat文档进行配置

浏览器中输入http://localhost:8080/-->Tomcat DocumentationàconfigurationàContext

配置方法1

In the $CATALINA_BASE/conf/context.xml file: the Context element information will be loaded by all webapps.

备注:可以被所有的web应用所共享

配置方法2

In the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all webapps of that host.

备注:被整个虚拟主机所共享

配置方法3:

In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml extension) will be used as the context path. Multi-level context paths may be defined using #, e.g. foo#bar.xml for a context path of /foo/bar. The default web application may be defined by using a file called ROOT.xml

备注:在tomcatàconfàcatalinaàlocalhostà a.xml 文件  a为浏览器的访问路径

Axml中的内容如下

<Context docBase="E:\vituralList"/>

分目录访问 xml的命名为:a#b#c.xml 浏览器访问路径是:http://localhost:8080/a/b/c/success.jsp

定义一个缺省的web应用 命名格式为ROOT.xml

配置方法4

Inside a Host element in the main conf/server.xml.

备注:不建议的方法 。因为要重启服务器

配置虚拟主机

打开tomcatserver.xml 在里面添加

<host name=”www.sina.com” appBase=”c:\sina”></host>

在这个host里面可以放多个web应用 供外界访问

配置虚拟主机+虚拟目录案例:

1.       tomcatservler.xml 文件中配置如下信息:

   <Host name="www.fangyang.com" appBase="E:\myhost">

             <Context path="/mail" docBase="E:\myhost\mail"/>

             <Context path="/news" docBase="E:\myhost\news"/>

      </Host>

2.        分别在E盘中建文件夹

3.       C:\Windows\System32\drivers\etc hosts 中加入  127.0.0.1  www.fangyang.com

4.       浏览器进行访问www.fangyang.com 为路径找不到页面(原因是没有配置默认主页,可以把path为空,设置为默认web应用,然后在默认web应用中配个页面即可)。

5.       wwww.fangyang.com/new/n.html 访问页面中的信息 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics