Multiple domains on single apache tomcat

泪湿孤枕 提交于 2019-12-24 00:11:50

问题


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?


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!