Page tree
Skip to end of metadata
Go to start of metadata
Your Rating: Results: 1 Star2 Star3 Star4 Star5 Star 128 rates

To modify Tomcat in order to set up Virtual Hosts for webapps to respond to specific DNS names. For example, you can change:

www.example.com/magnoliaPublic
www.example.com/magnoliaAuthor

to

www.example.com (public)
author.example.com (author)

Here are the steps:

1. Shutdown Tomcat

Back everything up just in case there is total meltdown and you need to revert to pre-hosts state.

2. Open ${catalina.home}/conf/server.xml. Change:

    <Engine name="Catalina" defaultHost="localhost" debug="0">

to

    <Engine name="Catalina" defaultHost="www.example.com" debug="0">

3. Change this:

      <Host name="localhost" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

to

      <Host name="www.example.com" debug="0" appBase="public"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

4. Change the end of the file from:

        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="localhost_log." suffix=".txt"
            timestamp="true"/>
      </Host>
    </Engine>
  </Service>

To:

        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="public_log." suffix=".txt"
            timestamp="true"/>
      </Host>
      <Host name="author.example.com" debug="0" appBase="author"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="author_log." suffix=".txt"
            timestamp="true"/>
      </Host>
    </Engine>
  </Service>

5. In the file system create the directories ${catalina.home}/public and ${catalina.home}/author

6. Rename webapps

Move ${catalina.home}/webapps/magnoliaAuthor to ${catalina.home}/author/ROOT

and ${catalina.home}/webapps/magnoliaPublic to ${catalina.home}/public/ROOT

7. Fix subscribers step 1

In the file system create the directories

${catalina.home}/conf/Catalina/www.example.com

${catalina.home}/conf/Catalina/author.example.com

In the www folder, create the file ROOT.xml with this line:

<Context path="" docBase="$\{catalina.home}/public/ROOT" />

In the author folder, create the file ROOT.xml with this line:

<Context path="" docBase="${catalina.home}/author/ROOT" />

(See Running Magnolia in the root of a host)

8. Start Tomcat.

Make sure www.example.com and author.example.com load in a web browser.

9. Fix subscribers step 2

In Admin Central for the author instance (open author.example.com in a web browser), change Config/SubscriberConfig/www.example.com/address to www.example.com (old value was www.example.com:/magnoliaPublic) and the senderURL to http://author.example.com

Test activating a page from author to public.

(See Running Magnolia in the root of a host)

10. Fix all templates with hardcoded context/webapp paths.

Example:

href="/magnoliaPublic/contact"

must be changed to:

href="${pageContext.request.contextPath}/contact"

You may also want to search your template scriptlets and make sure they use "request.getContextPath()" instead of hard coded context paths.

11. Fix all templates that link to the default uri.

Example:

href="${pageContext.request.contextPath}"

must be changed to:

href="${pageContext.request.contextPath}/"

Why? Because when you change magnoliaPublic to ROOT, you are eliminating the webapp name. So:

${pageContext.request.contextPath} = ""

Which means:

href="${pageContext.request.contextPath}"

turns into

href=""  (BAD!)

What you really want is:

href="${pageContext.request.contextPath}/"

which turns into

href="/"  (Correct!)

In its previous incarnation on JspWiki, this page was last edited on Feb 9, 2007 11:00:54 AM by JamesReynolds