マルチドメインアクセス
仮想ホスト構成、リソースの利用率を向上させます。
ポートに基づいて、複数の仮想ホストを設定することができますTomcatのserver.xmlファイルには、ホストノードを増加させることによって達成することができ、同じドメインに基づいて、サービスノードを増やすことによって達成することができます
ドメイン名ベースの仮想マシン
#编辑server.xml文件,在Engine段下添加Host段,如下:
#访问时使用name后的参数当作域名访问。
[root@smbands conf]# vi server.xml
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
................................................................
</Host>
添加一下几行
<Host name="www.smbands.com" appBase="/smbands" unpackWARs="true" autoDeploy="true">
<Context path="" docBase='.' debug="0" />
</Host>
#创建项目
[root@smbands ~]# mkdir /smbands
[root@smbands ~]# echo 'www.smbands.com' > /smbands/index.html
[root@smbands ~]# mkdir /usr/local/tomcat/webapps/test
[root@smbands ~]# echo 'www.borshman.com' > /usr/local/tomcat/webapps/test/index.html
#修改hosts文件,启动tomcat。
#访问测试
[root@smbands ~]# /usr/local/tomcat/bin/startup.sh
[root@smbands ~]# curl http://localhost:8080/smbands/
www.borshman.com
[root@smbands ~]# curl http://www.smbands.com:8080
www.smbands.com
ポートベースの仮想マシン
#编辑server.xml文件,在server段下添加service段,如下:
[root@smbands conf]# vi server.xml
<Service>
<Connector protocol="HTTP/1.1"
port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="second" debug="0">
<Host name="www.smbands.com" appBase="/demo"
unpackWARs="true" autoDeploy="true">
<Context path='' docBase="." debug="0"/>
</Host>
</Engine>
</Service>
#创建项目
[root@smbands ~]# mkdir /demo
[root@smbands ~]# echo 'www.smbands.com' > /demo/index.html
[root@smbands ~]# mkdir /usr/local/tomcat/webapps/test
[root@smbands ~]# echo 'www.borshman.com' > /usr/local/tom/webapps/test/index.html
#修改hosts文件,启动tomcat。
#访问测试
[root@smbands ~]# curl http://localhost:8080/test/
www.borshman.com
[root@smbands ~]# curl http://localhost:8081
www.smbands.com