Tomcat/mod_webapp question

Tomcat/mod_webapp question

Post by JDR » Mon, 24 Dec 2001 20:44:21



Hey all,
    I know you have seen tons of requests for help with mod_webapp configs,
but I think that this question is a bit different :)  I have tomcat working
successfully with mod_webapp forwarding requests for a particular virtual
host to tomcat.  I am able to view all of the example servlets and JSPs
included with the distribution.   Here is my question--how do I configure
tomcat/webapp to handle applications for multiple different virtual hosts?
Currently, I have something similar to the following in httpd.conf:

<VirtualHost xx.xx.xx.xx>
DocumentRoot /home/user/public_html
ServerName domain.com
ServerAlias www.domain.com
snip other Apache directives not relevant to the current example
WebAppConnection myconnection warp localhost:8008
WebAppDeploy examples myconnection /examples
WebAppDeploy tomcat-docs myconnection /tomcat-docs
</VirtualHost>

And, in server.xml:
<Service name="Tomcat-Apache">
<Connector className="org.apache.catalina.connector.warp.WarpConnector"
     port="8008" minProcessors="5" maxProcessors="10"
     enableLookups="false" acceptCount="10" debug="0"/>
<!-- Replace "localhost" with what your Apache "ServerName" is set to -->
<Engine className="org.apache.catalina.connector.warp.WarpEngine"
     name="domain.com" debug="0" appBase="webapps">
<!-- Global logger unless overridden at lower levels -->
<Logger className="org.apache.catalina.logger.FileLogger"
   prefix="apache_log." suffix=".txt" timestamp="true"/>
<!-- Because this Realm is here, an instance will be shared globally -->
<Realm className="org.apache.catalina.realm.MemoryRealm" />
</Engine>
</Service>

The directory structure of the user's home directory is as follows:
public_html
    \
    webapps (as mentioned in the appBase statement in server.xml)
        \
   examples, etc (as named in the WebAppDeploy statements in httpd.conf)

Everything works as I would expect it to at this point.  I can browse to
www.domain.com/examples/ and view the examples.  I can browse to
www.domain.com/tomcat-docs and view the tomcat documentation.

Here is the actual question portion of my question...if I want to have
another domain using servlets/JSP, how would I configure that?  For example,
a second VirtualHost named domain2.com, where that user would have their own
webapps directory structure in their own home directory.  Would I need to
create a new Apache-Connector service in server.xml on a different port
(8009 for example) specifying a different engine name (domain2.com instead
of domain1.com) and then a similar setup in httpd.conf specifying a
different connection name and port in WebAppConnection?  I guess I am just
really confused because of the statement in server.xml which states "Replace
localhost with what your apache ServerName is set to".  The ServerName is
going to be different based on the virtualhost, so it sounds like I need to
have separate connectors running on different ports for each virtualhost.
If someone could clear this up for me that would be great.  If you need more
info or are confused by my statements, please follow-up and I will attempt
to clarify.

Happy holidays to all,
Jay

 
 
 

Tomcat/mod_webapp question

Post by Nikola Milutinovi » Tue, 25 Dec 2001 17:38:38



Quote:> The directory structure of the user's home directory is as follows:
> public_html
>     \
>     webapps (as mentioned in the appBase statement in server.xml)
>         \
>    examples, etc (as named in the WebAppDeploy statements in httpd.conf)

It is unrecomended to place your web application directory under public_html
tree. I know that with WebAppDeploy your hiding that directory and noone can
access it via Apache, but it is error-prone. You don't exactly have a good
reason for placing that directory there. I know it looks interesting to have
JSP under the HTML tree, but in all reality, Web Application is a separate
entity from the rest of the Apache's tree.

Personally, I create the following for a virtual host:

- user dir (account holding the virtual host)
- $USER/public_html (holding Apache's HTML and static files)
- $USER/webapps (holding Tomcat's contexts - web applications)
- additional dirs (like sql, data, work,...)

In Tomcat I setup a virtual host:

<Host name="test.virtual.host.name.com" appBase="/usr/users/test/webapps">
...
<Loggers .../>
...
</Host>

In Apache I setup a virtual host, AND THIS IS WHERE I STILL HAVE A PROBLEM.

<IfModule mod_webapp.c>
       WebAppConnection tomcat4 warp localhost:8008
</IfModule>

<VirtualHost x.x.x.x>
ServerName test.virtual.host.com
DocumentRoot /usr/users/test/public_html
...
<IfModule mod_webapp.c>
   WebAppDeploy addr_book tomcat4 /addr_book/
</IfModule>
</VirtualHost>

Unfortunately, something breaks here, I get errors, but I'm convinced it
should be done this way. Test it and see what you come up with. I'm
curious - is it just me or is there something wrong with my compiles.

Nix.

 
 
 

Tomcat/mod_webapp question

Post by JDR » Tue, 25 Dec 2001 22:07:40





> > The directory structure of the user's home directory is as follows:
> > public_html
> >     \
> >     webapps (as mentioned in the appBase statement in server.xml)
> >         \
> >    examples, etc (as named in the WebAppDeploy statements in httpd.conf)

> It is unrecomended to place your web application directory under
public_html
> tree. I know that with WebAppDeploy your hiding that directory and noone
can
> access it via Apache, but it is error-prone. You don't exactly have a good
> reason for placing that directory there. I know it looks interesting to
have
> JSP under the HTML tree, but in all reality, Web Application is a separate
> entity from the rest of the Apache's tree.

> Personally, I create the following for a virtual host:

> - user dir (account holding the virtual host)
> - $USER/public_html (holding Apache's HTML and static files)
> - $USER/webapps (holding Tomcat's contexts - web applications)
> - additional dirs (like sql, data, work,...)

Perhaps you are correct, and if this is the case, I will alter my practices,
but as you do mention later you are having problems with this setup.  I will
test it out after Christmas when I have a few minutes and give you a second
opinion.  However, it was my understanding (limited as that may be) that
Tomcat (or mod_webapp) actually somehow uses a combination of the
DocumentRoot from the virtualhost and the appBase from server.xml to
determine where the base directory for the applications are.  If the webapps
directory is above the document root (defined in both of our cases as
public_html), perhaps that is why Tomcat cannot find the apps.  I could be
way off base here, but this is my theory.

Regards (and happy holidays to all),
Jay

 
 
 

Tomcat/mod_webapp question

Post by Nikola Milutinovi » Thu, 27 Dec 2001 17:14:30


Quote:> > Personally, I create the following for a virtual host:

> > - user dir (account holding the virtual host)
> > - $USER/public_html (holding Apache's HTML and static files)
> > - $USER/webapps (holding Tomcat's contexts - web applications)
> > - additional dirs (like sql, data, work,...)

> Perhaps you are correct, and if this is the case, I will alter my
practices,
> but as you do mention later you are having problems with this setup.

The setup is fine, I'm having problems with lacking documentation on
mod_webapp and almost zero support.

Quote:>  I will
> test it out after Christmas when I have a few minutes and give you a
second
> opinion.  However, it was my understanding (limited as that may be) that
> Tomcat (or mod_webapp) actually somehow uses a combination of the
> DocumentRoot from the virtualhost and the appBase from server.xml to
> determine where the base directory for the applications are.  If the
webapps
> directory is above the document root (defined in both of our cases as
> public_html), perhaps that is why Tomcat cannot find the apps.  I could be
> way off base here, but this is my theory.

Hmm, maybe. Basically, what I do not know and it is not documented anywhere
is:

- Apache has it's own virtual hosts test.company.com, www.company.com
- Tomcat has it's own virtual hosts test.company.com, ana.company.com

If I want to map an URL in Apache's VirtualHost to Tomcat's
VirtualHost/WebApp how do I specify it? "WebAppDeploy" has only "WebAppName"
as a parameter and I'm not sure what form it can take. Hell, I'm not sure
what the syntax is.

What I'm saying is, suppose Tomcat has 2 virtual hosts, as in the example
above, and BOTH of them have a context with the same path, like this:

http://test.company.com:8080/test_site/
http://ana.company.com:8080/test_site/

What do I do If I want to map one of these through mod_webapp? What does
this do:

<VirtualHost 192.168.61.16:80>
ServerName test.company.com
WebAppDeploy test_site tomcat-conn /test/my_test/
...
</VirtualHost>

Does it map only from specified Apache's VirtualHost to that same Tomcat's
host? What if I want to map to some other Tomcat's host?

Nix.