Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Apache Tomcat »

RE: Virtual Hosts [mostly solved]

Gormley, Josh

2006-12-28

Replies:

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@(protected)]
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 <miki@(protected)>



---------------------------------------------------------------------
To start a new topic, e-mail: users@(protected)
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.