Tomcat域名绑定

域名绑定与虚拟目录设置: 
conf/server.xml 的修改方式以下:html

单个域名绑定: 
原始: web

<Engine name="Catalina" defaultHost="localhost"> 
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" /> 
</Engine> 

固然这里我把注释代码通通删除掉了,省的碍眼 tomcat

修改后:app

<Host name="chengqun.202.71one.com" debug="0" appBase="d:\wwwroot\chengqun" 
unpackWARs="true" autoDeploy="true" 
xmlValidation="false" xmlNamespaceAware="false"> 
<Context path="/" docBase="d:\wwwroot\chengqun"></Context> 
</Host> 
<Host name="chengqun1.202.71one.com" debug="0" appBase="d:\wwwroot\chengqun1" 
unpackWARs="true" autoDeploy="true" 
xmlValidation="false" xmlNamespaceAware="false"> 
<Context path="/" docBase="d:\wwwroot\chengqun1"></Context> 
</Host>

多域名绑定:webapp

<Host name="chengqun.202.71one.com" debug="0" appBase="d:\wwwroot\chengqun" 
unpackWARs="true" autoDeploy="true" 
xmlValidation="false" xmlNamespaceAware="false"> 
<Alias>chengqun.202.71one.com</Alias> 
<Alias>chengqun1.202.71one.com</Alias> 
<Alias>chengqun2.202.71one.com</Alias> 
<Context path="/" docBase="d:\wwwroot\chengqun"></Context> 
</Host> 

这里面的参数还有不少,我也不是很清楚,不过这样作确实能够实现多域名绑定哈哈.并且网站页面修改了只要直接覆盖就能够了,tomcat能够自动更新类和页面,固然若是修改了web.xml或lib,则须要重启tomcat才能够.jsp

(二)虚拟目录网站

 

<Host name="chengqun.202.71one.com" debug="0" appBase="d:\wwwroot\chengqun" 
unpackWARs="true" autoDeploy="true" 
xmlValidation="false" xmlNamespaceAware="false"> 
<Context path="/chengqun" docBase="d:\wwwroot\chengqun"></Context> 
</Host> 

其中,Host标记是用来配置虚拟主机的,就是能够多个域名指向一个tomcat,格式只要参考默认的就 能够了。 
<context>是Host标记的子元素吧,表示一个虚拟目录,它主要有两个属性,path就至关于虚拟目录名字, 
而 docbase则是具体的文件位置。在这里个人虚拟路径名称为chengqun,实际上个人程序也就是html、jsp、servlet都 放在了d:\wwwroot\chengqun这个目录下了。 
这样我就能够经过 chengqun.202. com/chengqun 访问个人这个虚拟目录了。spa

另一种方法是:debug

 

<Host name="chengqun.202. com" debug="0" appBase="d:\wwwroot\chengqun" 
unpackWARs="true" autoDeploy="true" 
xmlValidation="false" xmlNamespaceAware="false"> 
<Context path="/" docBase="d:\wwwroot\chengqun"></Context> 
</Host>

这样设置之后,输入域名能够访问这个站点程序了(Context path="/"这里不一样)code

没有指定默认站点,因此直接输入IP的时候,没法访问。如何让输入ip就能够访问指定的站点呢? 修改server.xml的 <Engine name="Catalina" defaultHost="chengqun.202. com"> 这样就能够实现了输入ip访问chengqun.202. com这个站点的程序了!

相关文章
相关标签/搜索