Tomcat虚拟主机

虚拟主机用在一台物理机上搭建多个web站点,且互不影响

基于域名的主机

  • 根据来访问的域名解析对应每个不同的web站点
  • 配置域名与ip的映射管理(hosts)
    在host文件中添加对应的ip域名17,19
    vim /etc/hosts
    192.168.200.19  www.linuxxu.com
    192.168.200.18  www.cloud.com
    
  • 修改server.xml创建host模块对应域名
    vim /usr/local/tomcat8/conf/server.xml 
    <Host name="www.linuxxu.com"  appBase="webapps"
              unpackWARs="true" autoDeploy="true">
                  <Context docBase="/web/linuxxu" path="" reloadable="flase">            
                  </Context>
    
          <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                 prefix="localhost_access_log" suffix=".txt"
                 pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    
        </Host>
    
        <Host name="www.whml.com"  appBase="webapps"
              unpackWARs="true" autoDeploy="true">
                  <Context docBase="/web/whml" path="" reloadable="flase">  
                  </Context>
    
          <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                 prefix="localhost_access_log" suffix=".txt"
                 pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    
        </Host>
    
    
  • 创建域名对应路径
    mkdir -pv /web/{linuxxu,cloud}
    #对应创建index.jsp文件
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    
JSP test page <% out.println("Welcome to test site,http://www.对应域名.com");%> ```
  • 测试页面

基于端口的主机

  • 修改server.xml配置文件
    <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.jalja1.org"  appBase="E:/学习/activeMq/app1" unpackWARs="true" autoDeploy="true">
              <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="8888" protocol="HTTP/1.1"  connectionTimeout="20000" redirectPort="8443" />
      <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
      <Engine name="Catalina2" defaultHost="localhost">
        <Realm className="org.apache.catalina.realm.LockOutRealm">
          <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
        </Realm>
          <Host name="www.jalja1.org"  appBase="E:/学习/activeMq/app2" unpackWARs="true" autoDeploy="true">
              <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>
    

基于ip的主机

  • 配置多个子网接口,一一对应rever.xml里的web站点

Tomcat多实例配置

posted @ 2021-09-23 19:29  whml  阅读(203)  评论(0编辑  收藏  举报