360SDN.COM

首页/Tomcat/列表

tomcat单机多实例

来源:阿铭linux  2017-09-11 11:51:28    评论:0点击:

新朋友请点上方 蓝字“阿铭linux”关注

需求是: 同一个tomcat服务下,可以访问多个域名。

先来看看tomcat配置文件server.xml的结构

<Server>

    <Service name=”xxx”>

        <Host  name=”aaa.com” appBase=”dir1″>

        </Host>

    </Service>

<Server>

说明:

Service下面可以定义监听的端口,包含了<Host></Host>,而<Host></Host>里面定义虚拟主机,即,定义站点的域名和站点的目录。

两种方案:

1 可以在<Service></Service>里面定义多个<Host></Host>,这样就定义了多个站点,但端口不能变。

2 可以在<Server></Server>里面定义多个<Service></Service>,<Service></Service>里再定义<Host></Host>,这样做的好处是,可以更改监听端口。

假设需求为:

同一个服务器上跑两个站点

www.aaa.com  监听端口是8080

www.bbb.com  监听端口是8081

配置文件内容为:

<GlobalNamingResources>
<!– Editable user database that can also be used by
UserDatabaseRealm to authenticate users
–>
<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>

<!– A “Service” is a collection of one or more “Connectors” that share
a single “Container” Note: A “Service” is not itself a “Container”,
so you may not define subcomponents such as “Valves” at this level.
Documentation at /docs/config/service.html
–>
<Service name=”Catalina”>

<Connector port=”8080″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”8443″ />
<Connector port=”8009″ protocol=”AJP/1.3″ redirectPort=”8443″ />

<Engine name=”Catalina” defaultHost=”localhost”>

<Realm className=”org.apache.catalina.realm.LockOutRealm”>
<Realm className=”org.apache.catalina.realm.UserDatabaseRealm”
resourceName=”UserDatabase”/>
</Realm>

<Host name=”www.aaa.com” appBase=”webapps”
unpackWARs=”true” autoDeploy=”true”>

<Valve className=”org.apache.catalina.valves.AccessLogValve” directory=”logs”
prefix=”aaa.com_access” suffix=”.log”
pattern=”%h %l %u %t &quot;%r&quot; %s %b” />

</Host>
</Engine>
</Service>

<Service name=”aming”>

<Connector port=”8081″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”8443″ />

<Engine name=”aming” defaultHost=”localhost”>

<Realm className=”org.apache.catalina.realm.LockOutRealm”>
<Realm className=”org.apache.catalina.realm.UserDatabaseRealm”
resourceName=”UserDatabase”/>
</Realm>

<Host name=”www.bbb.com” appBase=”/data/tomcat”
unpackWARs=”true” autoDeploy=”true”>

<Valve className=”org.apache.catalina.valves.AccessLogValve” directory=”logs”
prefix=”bbb.com_access” suffix=”.log”
pattern=”%h %l %u %t &quot;%r&quot; %s %b” />

</Host>
</Engine>
</Service>

</Server>

- END -

出品 | 阿铭linux


  



私人微信:81677956  验证:公众号   

提升自己,才是世界上最稳健的投资

阅读原文

为您推荐

友情链接 |九搜汽车网 |手机ok生活信息网|ok生活信息网|ok微生活
 Powered by www.360SDN.COM   京ICP备11022651号-4 © 2012-2016 版权