Gerry
Gerry

Reputation: 1246

How to configure Tomcat with multiple domains; www mapping to wrong domain

I don't know much about Tomcat but I'm trying to get it going anyway. We have a Tomcat setup which started with a single domain, but later we added another ('mysite.net'). Our server.xml looks like:

  <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
    <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="mysite.net" appBase="webapps/mysite" path="" unpackWARs="true" autoDeploy="true">
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
       prefix="mysite_access_log." suffix=".txt"
       pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  </Host>

mysite.com works okay - the problem is www.mysite.com resolves to our first site (found locally under /usr/share/tomcat/webapps/ROOT). Maybe the problem is fixed with .htaccess file? Is my server.xml config completely wrong?

Upvotes: 0

Views: 281

Answers (1)

Mark Olsson
Mark Olsson

Reputation: 320

If mysite.com and mysite.net are completely separate applications: Use a different folder for www.mysite.net, /usr/share/tomcat/mysite for example. Then use appBase="mysite" for the second site. That way you can have a ROOT.war for each one.

If mysite.com and mysite.net do the same thing: Add an alias under the host tag.

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Alias>www.mysite.net</Alias>
<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>

Upvotes: 1

Related Questions