虚拟主机
tomcat不支持基于不同IP的虚拟主机
基于域名的虚拟主机
一台物理机搭建多个web站点,每个站点独立运行互不干扰
多个域名解析到同一个IP地址,web服务器配置文件添加多个站点,各站点有自己的主机名。客户端请求时http协议请求包含了主机名信息,根据不同主机名访问不同站点
[root@localhost ~]# vim /etc/hosts
192.168.111.4 www.qiao.com
192.168.111.4 www.ying.com
#修改hosts文件,并且在客户端测试机上也是修改为同样的。
[root@localhost ~]# mkdir /web/{qiao,ying} -pv
[root@localhost ~]# vim /web/qiao/index.jsp
welcome www.qiao.com
[root@localhost ~]# vim /web/ying/index.jsp
welcome www.ying.com
[root@localhost ~]# vim /usr/local/tomcat8/conf/server.xml
<Host name="www.qiao.com" appBase="/web"
unpackWARs="true" autoDeploy="true">
<Context docBase="qiao" path="" reloadable="false">
</Context>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="www.ying.com" appBase="/web"
unpackWARs="true" autoDeploy="true">
<Context docBase="ying" path="" reloadable="false">
</Context>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
基于端口的虚拟主机
需要添加和虚拟主机的个数相对应数量的service组件
[root@localhost ~]# vim /usr/local/tomcat8/conf/server.xml
<Service name="Catalina1">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- Define an AJP 1.3 Connector on port 8009 -->
<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="localhost" appBase="/web"
unpackWARs="true" autoDeploy="true">
<Context docBase="qiao" path="" reloadable="false">
</Context>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
<Service name="Catalina2">
<Connector port="8090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8010" 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="localhost" appBase="/web"
unpackWARs="true" autoDeploy="true">
<Context docBase="ying" path="" reloadable="false">
</Context>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
客户机测试:192.168.111.4:8080
192.168.111.4:8090
转载于:https://www.cnblogs.com/joinbestgo/p/10795979.html
今天的文章tomcat虚拟主机分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/12144.html