Tomcat域名綁定


域名綁定與虛擬目錄設置: 
conf/server.xml 的修改方式如下:

單個域名綁定: 
原始: 

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

當然這里我把注釋代碼統統刪除掉了,省的礙眼 

修改后:

<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>

多域名綁定:

<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才可以.

(二)虛擬目錄

 

<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 訪問我的這個虛擬目錄了。

另外一種方法是:

 

<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="/"這里不同)

沒有指定默認站點,所以直接輸入IP的時候,無法訪問。如何讓輸入ip就可以訪問指定的站點呢? 
修改server.xml的 <Engine name="Catalina" defaultHost="chengqun.202. com"> 
這樣就可以實現了輸入ip訪問chengqun.202. com這個站點的程序了!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM