<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
appBase:站点根目录
例如:(括号内是html文件的内容)
c:\\.....\webapps\
ROOT\
WEB-INF\
index.html(webapps\ROOT\index)
WEB-INF\
index.htm(c:\index)
d:\test\
ROOT\
WEB-INF\
index.htm(d:test\ROOT\index)
WEB-INF\
index.html(d:\index)
一、不设置Context
1.url请求 http://localhost:8080/ 后,tomcat会在server.xml中查找name=localhost的Host。然后根据appBase的映射路径(webapps)“内”去寻找web站点,由于在Host中没有配置Context,所以tomcat会指定ROOT目录作为默认站点,从而执行ROOT下index。
请求后显示结果 :
webapps\ROOT\index
二、设置Context
1.<Context path="" docBase="D:\test" />
当请求http://localhost:8080/会把docBase指定的目录作为访问的web站点
请求后显示结果 :
d:\index
2.<Context path="" docBase="." />
当请求http://localhost:8080/会把webapps目录作为访问的web站点,因为"."指的是Host设置的appBase路径
请求后显示结果 :
c:\index
3.<Context path="/test" docBase="D:\test"/>
当请求http://localhost:8080/test/会把D:\test目录作为访问的web站点(这点其实是设置虚拟子目录)
请求后显示结果 :
d:\index
如果修改或者增加Host
<Host name="site" appBase="D:\test"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
一、不设置Context
1.url请求 http://site:8080/ 后,tomcat会在server.xml中查找name=site的Host。然后根据appBase的映射路径(D:\test)“内”去寻找web站点,由于在Host中没有配置Context,所以tomcat会指定ROOT目录作为默认站点,从而执行ROOT下index。
请求后显示结果 :
d:test\ROOT\index
二、设置Context
1.<Context path="" docBase="C:....\webapps" />
当请求http://site:8080/会把docBase指定的目录作为访问的web站点
请求后显示结果 :
c:\index
2.<Context path="" docBase="." />
当请求http://site:8080/会把D:\test目录作为访问的web站点,因为"."指的是Host设置的appBase路径
请求后显示结果 :
d:\index
3.<Context path="/test" docBase="C:....\webapps"/>
当请求http://site:8080/test/会把C:....\webapps目录作为访问的web站点(这点其实是设置虚拟子目录)
请求后显示结果 :
c:\index
*当然要在本地访问http://site:8080/ 还需要C:\WINDOWS\system32\drivers\etc\hosts内添加 127.0.0.1 site
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
appBase:站点根目录
例如:(括号内是html文件的内容)
c:\\.....\webapps\
ROOT\
WEB-INF\
index.html(webapps\ROOT\index)
WEB-INF\
index.htm(c:\index)
d:\test\
ROOT\
WEB-INF\
index.htm(d:test\ROOT\index)
WEB-INF\
index.html(d:\index)
一、不设置Context
1.url请求 http://localhost:8080/ 后,tomcat会在server.xml中查找name=localhost的Host。然后根据appBase的映射路径(webapps)“内”去寻找web站点,由于在Host中没有配置Context,所以tomcat会指定ROOT目录作为默认站点,从而执行ROOT下index。
请求后显示结果 :
webapps\ROOT\index
二、设置Context
1.<Context path="" docBase="D:\test" />
当请求http://localhost:8080/会把docBase指定的目录作为访问的web站点
请求后显示结果 :
d:\index
2.<Context path="" docBase="." />
当请求http://localhost:8080/会把webapps目录作为访问的web站点,因为"."指的是Host设置的appBase路径
请求后显示结果 :
c:\index
3.<Context path="/test" docBase="D:\test"/>
当请求http://localhost:8080/test/会把D:\test目录作为访问的web站点(这点其实是设置虚拟子目录)
请求后显示结果 :
d:\index
如果修改或者增加Host
<Host name="site" appBase="D:\test"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
一、不设置Context
1.url请求 http://site:8080/ 后,tomcat会在server.xml中查找name=site的Host。然后根据appBase的映射路径(D:\test)“内”去寻找web站点,由于在Host中没有配置Context,所以tomcat会指定ROOT目录作为默认站点,从而执行ROOT下index。
请求后显示结果 :
d:test\ROOT\index
二、设置Context
1.<Context path="" docBase="C:....\webapps" />
当请求http://site:8080/会把docBase指定的目录作为访问的web站点
请求后显示结果 :
c:\index
2.<Context path="" docBase="." />
当请求http://site:8080/会把D:\test目录作为访问的web站点,因为"."指的是Host设置的appBase路径
请求后显示结果 :
d:\index
3.<Context path="/test" docBase="C:....\webapps"/>
当请求http://site:8080/test/会把C:....\webapps目录作为访问的web站点(这点其实是设置虚拟子目录)
请求后显示结果 :
c:\index
*当然要在本地访问http://site:8080/ 还需要C:\WINDOWS\system32\drivers\etc\hosts内添加 127.0.0.1 site
本文详细介绍了Tomcat服务器中Host与Context元素的配置方法及其对网站部署的影响。通过不同的配置示例,展示了如何设置默认站点、虚拟目录及子目录。
1190

被折叠的 条评论
为什么被折叠?



