1

I have a Tomcat server that that I want to run multiple webapps each with a different domain name. Given the configuration below, I want to be able to connect to http://webapp1 and get to its webapp and http://webapp2 and get to that one.

Currently when I start tomcat with this configuration, it complains about multiple bindings on port 80 (which I thought wouldn't be a problem given different domains) and when I try to access any of them, regardless of the domain I enter, I get the first webapp.

How do I get this to work the way I intend?

<?xml version='1.0' encoding='utf-8'?>
<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="SERVICE_WEBAPP1">
    <Connector port="80" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="443"
               compression="on"
           address="webapp1" />
    <Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
               ciphers="SSL_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, 
            TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, 
            SSL_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, 
            SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA"
           keystoreFile="KEYSTOREFILE1"
               keystorePass="keypass1"
           keystoreType="PKCS12"
           useIPVHosts="true"
           address="webapp1" />
    <Connector port="8009" protocol="AJP/1.3" redirectPort="443" />
    <Engine name="SERVICE_WEBAPP1" defaultHost="webapp1" >
      <Host name="webapp1"  appBase="webapp1dir"
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">
      </Host>   
    </Engine>
  </Service>
  <Service name="SERVICE_WEBAPP2">
    <Connector port="80" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="443"
               compression="on"
           address="webapp2" />
    <Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
               ciphers="SSL_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, 
            TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, 
            SSL_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, 
            SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA"
           keystoreFile="KEYSTOREFILE2"
               keystorePass="keypass2"
           useIPVHosts="true"
           address="webapp2" />
    <Engine name="SERVICE_WEBAPP2" defaultHost="webapp2" >
      <Host name="webapp2"  appBase="webapp2dir"
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">
      </Host>
    </Engine>
  </Service>
</Server>
Drew
  • 243
  • 1
  • 7

2 Answers2

1

Proxy it with Apache using Name Based Virtual Hosts.

Use mod_proxy_ajp to make the connection from Apache to Tomcat and just setup AJP connectors, not HTTP connectors in Tomcat.

Doug
  • 646
  • 3
  • 8
1

Your read the docs. Yep, it can be THAT simple.

pyroscope
  • 231
  • 1
  • 3
  • Each one needs to use a different SSL keystore/cert/etc. I see the docs mention address based virtual hosts but it doesn't explain how to set these up. – Drew Mar 02 '12 at 00:56
  • Then you need to add unique IPs to your network interface, which makes it easy to bind each connector to the same port, each on their own IP. And that also avoids the certificate validation problems you'd get with "real" virtual hosts otherwise. – pyroscope Mar 02 '12 at 02:17