You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by br...@commaflex.com on 2001/04/08 04:03:03 UTC

apache vhost->mod_jk->servlet container

Hi All!

This is my first post, so bear with me.

I've been struggling with this problem for 
awhile.  I'm trying to get tomcat to handle 
servlet requests outside of 
$TOMCAT_HOME/webapps/WEB-INF.

I am trying to do this because I have multiple 
apache vhosts pointing to multiple server 
paths for what needs to be multiple servlet 
containers.  Here are some example server 
paths to 
demonstrate my point...

/home/domain1.com/servlet
/home/domain2.com/servlet

...I have already setup the following files 
like so and actually have jsp working in my 
multiple server paths no problem.  It's the 
servlet directories that aren't working and 
just give me error 
404.

httpd.conf...

*all irrelevant information stripped*

<VirtualHost 0.0.0.0:80>
DocumentRoot /home/thesovereigngroup.com/www/pu
blic_html
ServerName www.thesovereigngroup.com
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
</VirtualHost>

server.xml...

<Host name="www.thesovereigngroup.com">
<Context path="" 
docBase="/home/thesovereigngroup.com/www/public
_html" debug="0"/>
<Context path="/servlet" 
docBase="/home/thesovereigngroup.com/www/public
_html/servlet" debug="0"/>
</Host>

....despite what looks to me like a proper 
configuration, when I point my web browser at 
http://www.thesovereigngroup.com/servlet/servle
texample i get a 404 error.  I imagined at 
first 
this was because i didn't declare the servlet 
in web.xml.  So I copied it 
to /home/thesovereigngroup.com/www/public_html/
servlet and declared a servlet like so...

<servlet>
<servlet-name>
hello
</servlet-name>
<servlet-class>
HelloWorldExample
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
hello
</servlet-name>
<url-mapping>
 /hello
</url-mapping>
</servlet-mapping>

...no dice still didn't work.  There seems to 
be very little documentation on this sort of 
thing, and what it boils down to is I'm trying 
to make tomcat host multiple servlet 
containers.  Any 
ideas?

Brendon

Re: apache vhost->mod_jk->servlet container

Posted by Jeff Kilbride <je...@kilbride.com>.
Here's an example of the setup I have running (info changed to be
generic...)

httpd.conf:
<VirtualHost 1.2.3.4>
        ServerName www.tld.com
        DocumentRoot "/home/websites/tld"

        JkMount /servlet/* ajp13
        JkMount /*.jsp ajp13

        Alias /mywebapp "/path/to/your/webapp/mywebapp"
        <Directory "/path/to/your/webapp/mywebapp">
                allow from all
        </Directory>

        <Location "/mywebapp /WEB-INF">
                AllowOverride None
                deny from all
        </Location>

        <Location "/mywebapp /META-INF">
                AllowOverride None
                deny from all
        </Location>

</VirtualHost>

server.xml:
<!-- Virtual host setup -->
<Host name="www.tld.com" >
    <Context path=""
                   docBase="/path/to/your/webapp/mywebapp"
                   crossContext="false"
                   debug="0"
                    reloadable="true" >
    </Context>
</Host>
----------------------

I noticed you had the DocumentRoot for Apache set to the same directory as
your docBase. Is that really what you want? I usually try to keep these two
separate. Since the docBase represents the top-level of my webapp, I usually
alias the docBase to a relative path with a meaningful name -- so people
access it from the web as www.tld.com/mywebapp, as opposed to www.tld.com.
I'm not even sure if having the docBase and DocumentRoot the same will work.
I've never tried it that way. (Does anybody know?)

Also, you don't need to declare the "/servlet" context explicitly. The above
config will give the following:

www.tld.com
    access to DocumentRoot in httpd.conf
www.tld.com/mywebapp
    access to the docBase in server.xml
    ability to run JSP files in the docBase directory
www.tld.com/servlet
    access to servlets/JSP in your WEB-INF/classes directory
    ability to run servlets/JSP from WEB-INF/classes

Your servlet mappings in your web.xml file below are correct. I got all of
this from the Apache-Tomcat and mod_jk Howto's located here:

http://jakarta.apache.org/tomcat/jakarta-tomcat/src/doc/index.html

I had to read them a couple of times and switch back and forth through the
examples, before it really made sense.

Hope this helps!

--jeff

----- Original Message -----
From: <br...@commaflex.com>
To: <to...@jakarta.apache.org>
Sent: Saturday, April 07, 2001 7:03 PM
Subject: apache vhost->mod_jk->servlet container


> Hi All!
>
> This is my first post, so bear with me.
>
> I've been struggling with this problem for
> awhile.  I'm trying to get tomcat to handle
> servlet requests outside of
> $TOMCAT_HOME/webapps/WEB-INF.
>
> I am trying to do this because I have multiple
> apache vhosts pointing to multiple server
> paths for what needs to be multiple servlet
> containers.  Here are some example server
> paths to
> demonstrate my point...
>
> /home/domain1.com/servlet
> /home/domain2.com/servlet
>
> ...I have already setup the following files
> like so and actually have jsp working in my
> multiple server paths no problem.  It's the
> servlet directories that aren't working and
> just give me error
> 404.
>
> httpd.conf...
>
> *all irrelevant information stripped*
>
> <VirtualHost 0.0.0.0:80>
> DocumentRoot /home/thesovereigngroup.com/www/pu
> blic_html
> ServerName www.thesovereigngroup.com
> JkMount /*.jsp ajp13
> JkMount /servlet/* ajp13
> </VirtualHost>
>
> server.xml...
>
> <Host name="www.thesovereigngroup.com">
> <Context path=""
> docBase="/home/thesovereigngroup.com/www/public
> _html" debug="0"/>
> <Context path="/servlet"
> docBase="/home/thesovereigngroup.com/www/public
> _html/servlet" debug="0"/>
> </Host>
>
> ....despite what looks to me like a proper
> configuration, when I point my web browser at
> http://www.thesovereigngroup.com/servlet/servle
> texample i get a 404 error.  I imagined at
> first
> this was because i didn't declare the servlet
> in web.xml.  So I copied it
> to /home/thesovereigngroup.com/www/public_html/
> servlet and declared a servlet like so...
>
> <servlet>
> <servlet-name>
> hello
> </servlet-name>
> <servlet-class>
> HelloWorldExample
> </servlet-class>
> </servlet>
> <servlet-mapping>
> <servlet-name>
> hello
> </servlet-name>
> <url-mapping>
>  /hello
> </url-mapping>
> </servlet-mapping>
>
> ...no dice still didn't work.  There seems to
> be very little documentation on this sort of
> thing, and what it boils down to is I'm trying
> to make tomcat host multiple servlet
> containers.  Any
> ideas?
>
> Brendon
>