问题
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:
- I copied my websiteA.war as ROOT.war into the $CATALINA_HOME/webapps/ folder
- I also copied my websiteB.war as WebsiteB.war into the $CATALINA_HOME/webapps/ folder
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"
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
Restarted tomcat. The websiteA.com gets deployed under "/" and websiteB.com gets deployed unter "/websiteB"
- Entering www.websiteB.com arrives at "/" which means that websiteA is actually shown for websiteB.com
What am I doing wrong here?
回答1:
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!
来源:https://stackoverflow.com/questions/13113401/multiple-domains-on-single-apache-tomcat