天天看點

linux中設定虛拟域名

一、打開tomcat安裝目錄下conf/server.xml這個檔案

在server.xml文檔中找到

</Engine>

</Service> 

接着添加上面添加以下内容(暫時先說分為三種方式):

第一種:

<Host name="www.haokan946.cn" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> 

<Context path="" docBase="www" debug="0" reloadable="true" crossContext="true"/> 

<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="www_5sai_log." suffix=".txt" 

timestamp="true"/> 

</Host>

以上的内容就是在Tomcat的webapps目錄下建立一個www檔案夾作為www.haokan946.cn這個域名的主目錄

第二種:

<Host name="test.5sai.net.cn" debug="0" appBase="C://test/www" unpackWARs="true" autoDeploy="true">

<Context path="" docBase="."/> 

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="test_5sai_access_log."

suffix=".txt" pattern="common" resolveHosts="false"/>

<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="test_5sai_log." suffix=".txt" timestamp="true"/>

以上内容的意思就是在C槽test檔案夾下面建立一個www檔案夾作為test.5sai.net.cn這個域名的主目錄

第三種,如果是linux系統的/var/www作為test.5sai.net.cn這個域名的主目錄的話内容如下:

<Host name="test.5sai.net.cn" debug="0" appBase="/var/www" unpackWARs="true" autoDeploy="true">

再補充一種

<Host name="www.haokan946.cn" debug="0" unpackWARs="true"> 

<Valve className="org.apache.catalina.valves.AccessLogValve" 

directory="/var/log/tomcat" prefix="www_5sai_access_log." suffix=".txt" 

pattern="common"/> 

<Logger className="org.apache.catalina.logger.FileLogger" 

directory="/var/log/tomcat" prefix="www_5sai_log." suffix=".txt" 

<Context path="" docBase="/var/www" debug="0" reloadable="true"/> 

域名www.haokan946.cn的主目錄為/var/www 該站點的所有通路LOG放在/ar/log/tomcat裡面

測試:

windows使用者打開C:/WINDOWS/system32/drivers/etc的hosts這個檔案,

linux使用者打開/ect的hosts檔案或者vi /ect/hosts

修改内容如下

127.0.0.1 localhost

127.0.0.1 www.haokan946.cn

127.0.0.1 test.5sai.net.cn

然後打開浏覽器直接輸入網址測試!

繼續閱讀