You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mike Curwen <gb...@gb-im.com> on 2003/09/03 22:07:35 UTC

JKMount, virtual hosts, and avoiding the webapp name

I'm not sure I'm configuring things quite correctly, because it seems to
me I should be able to do this with one less token...
 
Apache 2
TC 4.1.24
JK

My workers.properties:
worker.list=tomcat1
worker.tomcat1.port=11009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13


I define an Apache Virtual Host in httpd.conf:
<VirtualHost xxx.xxx.xxx.xxx>
   JKMount /ATM tomcat1
   JKMount /ATM/* tomcat1
   DocumentRoot /home/webhome/atm/htdocs/
   ServerName www.foo.com
   ServerAlias foo.com
   ErrorLog /var/log/atm/error_log
   CustomLog /var/log/atm/access_log combined
</VirtualHost>

And in Tomcat server.xml:
(inside the localhost 'host' element)

<Context path="/ATM"
	 docBase="/home/webhome/atm/"
	 defaultSessionTimeOut="60"
       reloadable="true" >
</Context>
 

So now to access regular static pages with apache, I just say:
http://www.foo.com/xyz.html
http://www.foo.com/pages/morepages/foo.html
 
And to do servlet/jsp stuff:
http://www.foo.com/ATM/servletFoo
http://www.foo.com/ATM/foo.jsp
http://www.foo.com/ATM/administer/admin.jsp
 
This works fairly well, I suppose, but what about sites where MOST
content is jsp/servlet based?
 
I'd like my URLS to not require the /ATM token.
 
So then I thought to do this (in apache):
<VirtualHost xxx.xxx.xxx.xxx>
   JKMount /*.jsp tomcat1
   JKMount /*/*.jsp tomcat1
   JKMount /servletFoo tomcat1
   DocumentRoot /home/webhome/atm/htdocs/
   ServerName www.foo.com
   ServerAlias foo.com
   ErrorLog /var/log/atm/error_log
   CustomLog /var/log/atm/access_log combined
</VirtualHost>
 
But....  how do I match up the requests from apache's virtual host
www.foo.com to the /ATM context in Tomcat?  Am I looking at creating a
new <Host> in Tomcat for each <VirtualHost> in apache?
 
And then the default webapp for each of my TC Hosts would be the /ATM
application?
 
Thanks for any pointers.



Re: JKMount, virtual hosts, and avoiding the webapp name

Posted by John Turner <to...@johnturner.com>.
Mike Curwen wrote:

> 
> So it's gonna be something like:
> 
> The Apache Vhost:
> <VirtualHost xxx.xxx.xxx.xxx>
>    JKMount /*.jsp tomcat1
>    JKMount /fooservlet tomcat1
>    DocumentRoot /home/webhome/atm/htdocs/
>    ServerName www.foo.com
>    ServerAlias foo.com
>    ErrorLog /var/log/atm/error_log
>    CustomLog /var/log/atm/access_log combined
> </VirtualHost>
> 
> relates to the TC Host:
> <Host name="www.foo.com" debug="0" appBase="webapps" unpackWARs="true">
>  <Alias>foo.com</Alias>
>  <Context path="" docBase="home/webhome/atm" debug="0"
> reloadable="true"/>
> </Host>

Yeah, but I typically make DocumentRoot = ROOT docBase.  So on my 
servers I have something like this:

<Host name="www.VIRTHOST.com" debug="1" appBase="VIRTHOST" 
unpackWARs="true" autoDeploy="true">
     <Context path="" docBase="VIRTHOST" debug="0" reloadable="true">
     </Context>
</Host>

and

<VirtualHost *>
     ServerName www.VIRTHOST.aas.com
     DocumentRoot /usr/local/jakarta-tomcat-4.1.27/VIRTHOST/VIRTHOST

     # Static files
     Alias / "/usr/local/jakarta-tomcat-4.1.27/VIRTHOST/VIRTHOST"

     <Directory "/usr/local/jakarta-tomcat-4.1.27/VIRTHOST/VIRTHOST">
         Options Indexes FollowSymLinks
         DirectoryIndex index.jsp
     </Directory>

     # Deny direct access to WEB-INF and META-INF
     <Location "/WEB-INF/*">
         AllowOverride None
         deny from all
     </Location>
     <Location "/META-INF/*">
         AllowOverride None
         deny from all
     </Location>

     JkMount /* ajp13
</VirtualHost>

Which makes the following dir structure possible:

appBase
$CATALINA_HOME/VIRTHOST

Apache DocumentRoot, and TC root Context, path="", docBase="VIRTHOST":
$CATALINA_HOME/VIRTHOST/VIRTHOST

other Context, path="/SOME_OTHER_APP", docBase="SOME_OTHER_APP":
$CATALINA_HOME/VIRTHOST/SOME_OTHER_APP

Yes, #2 above is redundant with having the same dir name twice, but it 
makes sense to me.  You could just as easily change it to ROOT or 
something else, but in my case, with many virtual hosts, I found myself 
saying "ok, this is ROOT, but WHICH ROOT?".  Using the domain name as 
the actual name of the directory for the root web app gets rid of this 
problem.

For other Contexts, you just add additional Alias commands to httpd.conf 
to get Apache to recognize dirs on the same level as the DocRoot instead 
of sub-dirs.

> Is that correct?  In this case, I'm replacing /ATM and /BDG apps with to
> Hosts under TC, with the default Context set to be a separate instance
> of that 'common' app.

Pretty much, I would just watch the DocumentRoot and Alias in 
httpd.conf, they can play tricks on you if you have them pointing to 
directories one level above or below your Context's docBase.

> I'm wondering about this from workers.properties:
> 
>   worker.list=tomcat1
>   worker.tomcat1.host=localhost
>  
> Will I need to define a new work for each new host in TC,or can I supply
> a comma separated list to the worker.tomcat1.host entry?

No, you only need one worker.  ".host" = "location of machine running 
Tomcat", it does not need to match any virtual host name.  I used to 
think it did, back in the day, but I have since seen the error of my 
ways and have come back to the straight and narrow.  A basic 4-line 
workers.properties will work for many virtual hosts.  I have servers 
with 5, 8, and 22 virtual hosts, all using one worker per physical 
server with no problems.

>  
> Thanks very much John. :)

Glad to help, if I am.  Have fun.

John




RE: JKMount, virtual hosts, and avoiding the webapp name

Posted by Mike Curwen <gb...@gb-im.com>.
inlined replies...

> -----Original Message-----
> From: John Turner [mailto:tomcat-user@johnturner.com] 
> Sent: Wednesday, September 03, 2003 3:28 PM
> To: Tomcat Users List
> Subject: Re: JKMount, virtual hosts, and avoiding the webapp name
> 
> 

<snip />

> > But....  how do I match up the requests from apache's virtual host
> > www.foo.com to the /ATM context in Tomcat?  Am I looking at 
> creating a
> > new <Host> in Tomcat for each <VirtualHost> in apache?
> 
> Yes.
> 
> > And then the default webapp for each of my TC Hosts would 
> be the /ATM
> > application?
> 
> You mean sharing Contexts across Hosts?  I don't think so.
> 

Oops, I mispoke. We have a single application that we deploy multiple
contexts of, so that each virtual host has its own copy of the
application. So in my 'new' scheme, I'd specify that the default webapp
is this 'common' application, but not 'shared' in the sense you thought,
(because of my typing).

> Your Context path is just "" with the same docBase.  Then 
> your JkMounts are:
> 
> JkMount /*.jsp worker-name
> JkMount /something-typically-servlet/* ajp13
> 
> John
> 




So it's gonna be something like:

The Apache Vhost:
<VirtualHost xxx.xxx.xxx.xxx>
   JKMount /*.jsp tomcat1
   JKMount /fooservlet tomcat1
   DocumentRoot /home/webhome/atm/htdocs/
   ServerName www.foo.com
   ServerAlias foo.com
   ErrorLog /var/log/atm/error_log
   CustomLog /var/log/atm/access_log combined
</VirtualHost>

relates to the TC Host:
<Host name="www.foo.com" debug="0" appBase="webapps" unpackWARs="true">
 <Alias>foo.com</Alias>
 <Context path="" docBase="home/webhome/atm" debug="0"
reloadable="true"/>
</Host>


AND
<VirtualHost xxx.xxx.xxx.xxx>
   JKMount /*.jsp tomcat1
   JKMount /fooservlet tomcat1
   DocumentRoot /home/webhome/bdg/htdocs/
   ServerName www.foo2.com
   ServerAlias foo2.com
   ErrorLog /var/log/bdg/error_log
   CustomLog /var/log/bdg/access_log combined
</VirtualHost>

relates to the TC Host:
<Host name="www.foo2.com" debug="0" appBase="webapps" unpackWARs="true">
 <Alias>foo2.com</Alias>
 <Context path="" docBase="home/webhome/bdg" debug="0"
reloadable="true"/>
</Host>


 
Is that correct?  In this case, I'm replacing /ATM and /BDG apps with to
Hosts under TC, with the default Context set to be a separate instance
of that 'common' app.
 
I'm wondering about this from workers.properties:

  worker.list=tomcat1
  worker.tomcat1.host=localhost
 
Will I need to define a new work for each new host in TC,or can I supply
a comma separated list to the worker.tomcat1.host entry?
 
 
As for the 'illegal' and 'scary' mappings we have.. I'm sure we just
picked them up from googling and well, you know how valid some of the
info out there is.  We've also got some attributes on Contexts that I
can't find docos for. They don't seem to hurt though.  After I've ironed
out these issues, I'm doing a 'clean sweep' of all the files (after
backup of course) and 'HOWTO' for myself and colleagues at work. 
 
Thanks very much John. :)


Re: JKMount, virtual hosts, and avoiding the webapp name

Posted by John Turner <to...@johnturner.com>.
Mike Curwen wrote:

> 
> I define an Apache Virtual Host in httpd.conf:
> <VirtualHost xxx.xxx.xxx.xxx>
>    JKMount /ATM tomcat1
>    JKMount /ATM/* tomcat1

I wouldn't do /ATM without a wildcard or something after it.

>    DocumentRoot /home/webhome/atm/htdocs/
>    ServerName www.foo.com
>    ServerAlias foo.com
>    ErrorLog /var/log/atm/error_log
>    CustomLog /var/log/atm/access_log combined
> </VirtualHost>
> 
> And in Tomcat server.xml:
> (inside the localhost 'host' element)
> 
> <Context path="/ATM"
> 	 docBase="/home/webhome/atm/"
> 	 defaultSessionTimeOut="60"
>        reloadable="true" >
> </Context>
>  
> 
> So now to access regular static pages with apache, I just say:
> http://www.foo.com/xyz.html
> http://www.foo.com/pages/morepages/foo.html
>  
> And to do servlet/jsp stuff:
> http://www.foo.com/ATM/servletFoo
> http://www.foo.com/ATM/foo.jsp
> http://www.foo.com/ATM/administer/admin.jsp
>  
> This works fairly well, I suppose, but what about sites where MOST
> content is jsp/servlet based?
>  
> I'd like my URLS to not require the /ATM token.

You don't need it.

>  
> So then I thought to do this (in apache):
> <VirtualHost xxx.xxx.xxx.xxx>
>    JKMount /*.jsp tomcat1
>    JKMount /*/*.jsp tomcat1
>    JKMount /servletFoo tomcat1
>    DocumentRoot /home/webhome/atm/htdocs/
>    ServerName www.foo.com
>    ServerAlias foo.com
>    ErrorLog /var/log/atm/error_log
>    CustomLog /var/log/atm/access_log combined
> </VirtualHost>

Double wildcards is "illegal".  "/*.jsp" is equivalent to "/*/*.jsp" 
since the second "/" is covered by the "*" in "/*.jsp".

> But....  how do I match up the requests from apache's virtual host
> www.foo.com to the /ATM context in Tomcat?  Am I looking at creating a
> new <Host> in Tomcat for each <VirtualHost> in apache?

Yes.

> And then the default webapp for each of my TC Hosts would be the /ATM
> application?

You mean sharing Contexts across Hosts?  I don't think so.

Your Context path is just "" with the same docBase.  Then your JkMounts are:

JkMount /*.jsp worker-name
JkMount /something-typically-servlet/* ajp13

John