You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Gormley, Josh" <JG...@parts-unltd.com> on 2006/12/28 20:18:48 UTC

RE: Virtual Hosts [mostly solved]

With the help of several people on this list, I've been able to get my
server configured [mostly] the way I wanted it configured.  Here's my
solution, hopefully it will be helpful to others

Goals:
  * One instance of Tomcat running behind Apache
  * Multiple VirtualHosts, each pointing to its own Tomcat webapp
  * The ability to hot-deploy an app without affecting the other apps
  * Minimal or no modifications required to server.xml for additional
    hosts
  * A solution that is maintainable and is not a hack

Solution:
  * Apache with mod_jk
  * Each domain has a .conf file at /etc/httpd/conf.d/vhosts
    * The conf file routes .do and .jsp files to tomcat using mod_jk
        JkMount /*.do router
        JkMount /*.jsp router
    * The VirtualHost declaration has the DocumentRoot set to the path
      of the webapp
  * Tomcat's server.xml file has a host declaration for each webapp 
    and a declaration for localhost (though that is not necessary)
        <Host name="localhost" appBase="webapps" />
        <Host name="foo.mydomain.com" appBase="webapps/foo" />
        <Host name="bar.mydomain.com" appBase="webapps/bar" />
        <Host name="eggs.mydomain.com" appBase="webapps/eggs" />
  * Deploy a war file named ROOT.war to the correct appBase for each
    application.  This file must be named ROOT.war
  * GOTCHA: I tried to also include the manager webapp for each of the 
    hosts by adding the manager.xml file to 
    $CATALINA_HOME/conf/Catalina/foo.mydomain.com/ as described here
    http://webtuitive.com/samples/virtual-hosting-howto.jsp
    but by having a context defined in this location, I was not able 
    to deploy my applications using Automatic Application Deployment
    as defined in the Tomcat docs.  I'm not sure why this doesn't work
    but by removing the manager.xml file, I am able to hot-deploy my
    apps.

This is working well for me, and that in itself makes me happy.  The 
only things I'd like to improve upon are:
  * Not having to modify server.xml directly.  According to the Tomcat
    docs, you shouldn't modify this file.  I'm not sure how to avoid 
    this.
  * Being able to include the manager app for each host that I define.
I
    was using ant's tomcat tasks to tie into the manager for deploying
    my apps, but now I have to scp the war file into the directory.
    This isn't the worst thing that could happen, but it seems like 
    there is a solution out there for this.

Anyway, thanks to everybody who helped out on this.

Josh Gormley



-----Original Message-----
From: Mikolaj Rydzewski [mailto:miki@ceti.pl] 
Sent: Thursday, December 28, 2006 9:34 AM
To: Tomcat Users List
Subject: Re: Virtual Hosts

Gormley, Josh wrote:
> As a side question, is this possible to do without modifying the
> server.xml file every time I want to add a new host?  I've read that
> it's bad practice to modify the server.xml file much like it's bad
> practice to modify the httpd.conf file in Apache.  In Apache, I have a
> vhost directory with .conf files for each host -- is there a similar
> method to do this with Tomcat?
>   
There is a host-manager webapp which comes with Tomcat to allow adding 
vhosts on the fly (I haven't used it, however). You will need user with 
admin role in tomcat-users.xml to access it.

-- 
Mikolaj Rydzewski <mi...@ceti.pl>



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Virtual Hosts [mostly solved]

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Mark Eggers [mailto:its_toasted@yahoo.com] 
> Subject: RE: Virtual Hosts [mostly solved]
> 
> For a root context, I usually set up an
> application.xml file in conf/Catalina/<hostname>/ with
> the appropriate path="" in the Context element

That's incorrect for all recent versions of Tomcat.  You must not use a
path attribute unless the <Context> element is in server.xml, which is
strongly discouraged.  For the default app, place the <Context> element
with an appropriate docBase in a file named ROOT.xml inside each
conf/Catalina/[host] directory.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Virtual Hosts [mostly solved]

Posted by Mark Eggers <it...@yahoo.com>.
You may find that the default host loads all of the
web applications.

In order to solve this, make sure that each of the
contexts are not some subdirectory of another context.

<Host name="localhost" appBase="vhosts/local" />
<Host name="foo.mydomain.com" appBase="vhosts/foo" />
<Host name="bar.mydomain.com" appBase="vhosts/bar" />
<Host name="eggs.mydomain.com" appBase="vhosts/eggs"
/>

You can use an absolute path to place this structure
outside of your Tomcat installation.  For large
structures I think this is nice, because then you can
upgrade Tomcat without disturbing your applications. 
Cutover would involve installing a parallel Tomcat,
modifying server.xml. shutting down the old version,
and starting up the new version.  If the new version
failed, recovery is just shutting down the new version
and starting up the old version.

If you want a one-stop place for all of your web
applications, please ignore this comment.

For a root context, I usually set up an
application.xml file in conf/Catalina/<hostname>/ with
the appropriate path="" in the Context element, or a
context.xml file in the web application's META-INF
directory with the same context information.

Once you separate each of the virtual hosts so that
subdirectories don't overlap, I think you will find
that multiple manager applications work.  The manager
application will then be specific to the virtual host,
and you'll have to access that manager application by
going to the specific virtual host (ie,
http://<hostname>:8080/manager/html)

HTH

/mde/
. . . . . just my two cents

--- "Gormley, Josh" <JG...@parts-unltd.com> wrote:

> With the help of several people on this list, I've
> been able to get my
> server configured [mostly] the way I wanted it
> configured.  Here's my
> solution, hopefully it will be helpful to others
> 
> Goals:
>   * One instance of Tomcat running behind Apache
>   * Multiple VirtualHosts, each pointing to its own
> Tomcat webapp
>   * The ability to hot-deploy an app without
> affecting the other apps
>   * Minimal or no modifications required to
> server.xml for additional
>     hosts
>   * A solution that is maintainable and is not a
> hack
> 
> Solution:
>   * Apache with mod_jk
>   * Each domain has a .conf file at
> /etc/httpd/conf.d/vhosts
>     * The conf file routes .do and .jsp files to
> tomcat using mod_jk
>         JkMount /*.do router
>         JkMount /*.jsp router
>     * The VirtualHost declaration has the
> DocumentRoot set to the path
>       of the webapp
>   * Tomcat's server.xml file has a host declaration
> for each webapp 
>     and a declaration for localhost (though that is
> not necessary)
>         <Host name="localhost" appBase="webapps" />
>         <Host name="foo.mydomain.com"
> appBase="webapps/foo" />
>         <Host name="bar.mydomain.com"
> appBase="webapps/bar" />
>         <Host name="eggs.mydomain.com"
> appBase="webapps/eggs" />
>   * Deploy a war file named ROOT.war to the correct
> appBase for each
>     application.  This file must be named ROOT.war
>   * GOTCHA: I tried to also include the manager
> webapp for each of the 
>     hosts by adding the manager.xml file to 
>     $CATALINA_HOME/conf/Catalina/foo.mydomain.com/
> as described here
>    
>
http://webtuitive.com/samples/virtual-hosting-howto.jsp
>     but by having a context defined in this
> location, I was not able 
>     to deploy my applications using Automatic
> Application Deployment
>     as defined in the Tomcat docs.  I'm not sure why
> this doesn't work
>     but by removing the manager.xml file, I am able
> to hot-deploy my
>     apps.
> 
> This is working well for me, and that in itself
> makes me happy.  The 
> only things I'd like to improve upon are:
>   * Not having to modify server.xml directly. 
> According to the Tomcat
>     docs, you shouldn't modify this file.  I'm not
> sure how to avoid 
>     this.
>   * Being able to include the manager app for each
> host that I define.
> I
>     was using ant's tomcat tasks to tie into the
> manager for deploying
>     my apps, but now I have to scp the war file into
> the directory.
>     This isn't the worst thing that could happen,
> but it seems like 
>     there is a solution out there for this.
> 
> Anyway, thanks to everybody who helped out on this.
> 
> Josh Gormley
> 
> 
> 
> -----Original Message-----
> From: Mikolaj Rydzewski [mailto:miki@ceti.pl] 
> Sent: Thursday, December 28, 2006 9:34 AM
> To: Tomcat Users List
> Subject: Re: Virtual Hosts
> 
> Gormley, Josh wrote:
> > As a side question, is this possible to do without
> modifying the
> > server.xml file every time I want to add a new
> host?  I've read that
> > it's bad practice to modify the server.xml file
> much like it's bad
> > practice to modify the httpd.conf file in Apache. 
> In Apache, I have a
> > vhost directory with .conf files for each host --
> is there a similar
> > method to do this with Tomcat?
> >   
> There is a host-manager webapp which comes with
> Tomcat to allow adding 
> vhosts on the fly (I haven't used it, however). You
> will need user with 
> admin role in tomcat-users.xml to access it.
> 
> -- 
> Mikolaj Rydzewski <mi...@ceti.pl>
> 
> 
> 
>
---------------------------------------------------------------------
> To start a new topic, e-mail:
> users@tomcat.apache.org
> To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail:
> users-help@tomcat.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Virtual Hosts [mostly solved]

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Gormley, Josh [mailto:JGormley@parts-unltd.com] 
> Subject: RE: Virtual Hosts [mostly solved]
> 
>   * Not having to modify server.xml directly.  According to the Tomcat
>     docs, you shouldn't modify this file.

I think you may have misconstrued something in the docs.  There's
nothing wrong with modifying server.xml; for example, production
environments must change it and web.xml to remove development-oriented
attributes.  Certainly you should not place <Context> elements in
server.xml, since that requires a Tomcat restart to modify webapp
attributes.

>   * Tomcat's server.xml file has a host declaration for each webapp 
>     and a declaration for localhost (though that is not necessary)
>         <Host name="localhost" appBase="webapps" />

I would remove the <Host> entry for localhost, since, as someone else
pointed out, its appBase points to a parent directory of the other
<Host>s, and this is at best bad practice and confusing, even if not
necessarily causing errors.

>   * Being able to include the manager app for each host that I define.

I don't have a problem doing this.  All I did was place a copy of
manager.xml is each conf/Catalina/[host] directory, and all apps deploy
properly under each of their hosts.  Did you change something in
manager.xml?

- Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org