`

tomcat 多个项目 子域名

 
阅读更多

?

说明:

1.首先需要有多个域名,同时指向一个IP地址。

例如:域名www.bbb.com, www.aaa.com等等。

解析到一个公网IP地址:210.34.120.110.

2.需要对tomcat下的conf下的"server.xml"进行配置
<Server port="8005" shutdown="SHUTDOWN">

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

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

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

<!--以下配置是关键-->
<Engine name="Catalina" defaultHost="localhost">

<!--默认通过localhost转发-->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>

<!--以下是自带的转发-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

</Host>
<!-- 在tomcat安装目录下新建文件夹aaa 与webapp同级,然后在该目录下新建Root,项目内容可放在这个位置 -->
<Host name="www.aaa.com" appBase="aaa"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>

<!-- 同上,在tomcat安装目录下新建文件夹bbb与webapp同级 , 然后在该目录下新建Root,项目内容可放在这个位置 -->

<Host name="www.bbb.com" appBase="bbb"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>

</Engine>
</Service>
</Server>
这样,就可以访问多个项目,通过不同的域名进行。

附:如果进行本地测试。则需加如下配置:

C:\Windows\System32\drivers\etc\hosts(Vista系统下路径,其他操作系统可能不一样)

# Copyright (c) 1993-2006 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 www.aaa.com

127.0.0.1  www.bbb.com

127.0.0.1 localhost

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics