Multiple domains on single apache tomcat
Asked Answered
O

1

2

I have two domains but only one virtual server which runs a tomcat 7. I have my own ubuntu Linux with full root access running on the virtual server. I setup shorewall firewall which forwards any request on port 80 to port 8080 (where tomcat is listening on).

So I already searched the net but I only find "solution" that do not work in my case. This is what I did so far:

  1. I copied my websiteA.war as ROOT.war into the $CATALINA_HOME/webapps/ folder
  2. I also copied my websiteB.war as WebsiteB.war into the $CATALINA_HOME/webapps/ folder
  3. I modified my $CATALINA_HOME/conf/server.xml in the following way:

    Host name="www.websiteA.com" appBase="webapps" unpackWARs="true" autoDeploy="true"

    Host name="www.websiteB.de" appBase="webapps/websiteB" unpackWARs="true" autoDeploy="true"

    Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"

  4. I created the following file ROOT.xml in the folder "$CATALINA_HOME/conf/Catalina/www.websiteB.com" :

    ?xml version="1.0" encoding="UTF-8"?

    Context displayName="www.websiteB.com" docBase="" path=""

    /Context

  5. Restarted tomcat. The websiteA.com gets deployed under "/" and websiteB.com gets deployed unter "/websiteB"

  6. Entering www.websiteB.com arrives at "/" which means that websiteA is actually shown for websiteB.com

What am I doing wrong here?

Olva answered 28/10, 2012 at 21:55 Comment(2)
Hey, did you get an answer to this?Bilocular
Yeah, just updated this very old question with an answer.Olva
O
2

Goto your $CATALINA_HOME/conf/server.xml file.

There, you will find the following section:

<Engine name="Catalina" defaultHost="localhost">
    <!-- ... some other stuff ... -->
    <Host name="www.websiteA-Address" appBase="webapps" unpackWARs="true" autoDeploy="true"></Host>
    <Host name="www.websiteB-Address" appBase="directory/of/WAR-files-for-B" unpackWARs="true" autoDeploy="true"></Host>
    <Host name="websiteB-Address" appBase="directory/of/WAR-files-for-B" unpackWARs="true" autoDeploy="true"></Host>
    <Host name="www.websiteC-Address"  appBase="directory/of/WAR-files-for-C" unpackWARs="true" autoDeploy="true"></Host>
</Engine>

So, appBase will be the directory where your will have to put your ROOT.war(!) and name is the domain name that will be mapped onto this directory.

directory/of/WAR-files is a subdirectory in $CATALINA_HOME, that is the same level(!!!) as the standard folder webapps. So both directories coexist!

Olva answered 9/4, 2018 at 6:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.