說明:linux
1.首先須要有多個域名,同時指向一個IP地址。web
例如:域名:www.bbb.com, www.aaa.com等等。apache
解析到一個公網IP地址:xxx.xxx.xxx.xxxtomcat
2.須要對tomcat下的conf下的"server.xml"進行配置
<Server port="8005" shutdown="SHUTDOWN">app
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />webapp
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>ide
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="gbk" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />spa
<!--如下配置是關鍵-->
<Engine name="Catalina" defaultHost="localhost">3d
<!--默認經過localhost轉發-->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>server
<!--如下是自帶的轉發-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<!-- 在tomcat安裝目錄下新建文件夾aaa 與webapp同級,而後在該目錄下新建Root,項目內容可放在這個位置 -->
<Host name="www.qinyinbolan.com" appBase="aaa"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<!-- 同上,在tomcat安裝目錄下新建文件夾bbb與webapp同級 , 而後在該目錄下新建Root,項目內容可放在這個位置 -->
<Host name="linux.qinyinbolan.com" appBase="bbb"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
</Engine></Service></Server>這樣,就能夠訪問多個項目,經過不一樣的域名進行。