tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nikola Milutinovic" <>
Subject Re: mod_webapp and php
Date Tue, 22 Jan 2002 08:30:49 GMT
> > Thanks for clarification, Craig But then again, what if the static
> > content (e.g. some html pages) resides inside web-app, is it than
> > considered static? Will Apache serve it from there directly (I believe
> > not, cause it could be on a different host) or will mod_webapp pre-cache
> > it in some place Apache is aware of or will such content be served by
> > Tomcat? (that is what I think for now)
> >
> Your impression of how it works seems to be inaccurate.  There is no
> caching going on anywhere.
> Let's look at the Tomcat stand-alone case first, and then examine the
> combined case.
> Technically, from the point of view of Tomcat 4 (details are slightly
> different in 3.3), there is no such thing as "static content" -- all
> requests are handled by a servlet.  If you look in the
> $CATALINA_HOME/conf/web.xml file, which defines default configuration
> settings for all webapps, you will see a servlet named "default" that is
> mapped to the URL pattern "/".  This pattern means, "use the 'default'
> servlet whenever no other servlet is matched by a particular request URI".
> So, requests for things like "index.html" and "logo.jpg" don't match any
> of your application servlets or JSP pages, so they are handled by the
> default servlet -- which simply serves the contents of the corresponding
> file back to the client.

That was my understanding, too.

> Now, let's consider what happens when you put Apache and a web connector
> in front of Tomcat (the concepts apply equally to mod_jk and mod_webapp,
> only the configuration details differ).  Essentially, what people try to
> do is make Apache itself be the default file-serving servlet, instead of
> the one built in to Tomcat.

Because it is faster, yes.

> This is accomplished in your configuration directives, where you tell
> Apache which requests to forward (and by implication, all other requests
> are handled by Apache itself in the usual way).  Thus, when we add a
> diretive that says "forward all *.jsp requests to Tomcat", we are telling
> Apache that any request that ends with ".jsp" MUST be forwarded to Tomcat
> for processing.  Apache acts like a proxy server for these requests -- it
> just calls Tomcat and then copies back the response Tomcat creates to the
> original client.
> If you do not have any such configuration directives for "*.html" and
> "*.jpg" patterns, then Apache serves them directly, based on your Apache
> configuration directives in httpd.conf.  It is NOT an issue of pre-caching
> or anything like that -- the request either gets forwarded to Tomcat or it
> doesn't.

This means, that if I'm developing a web application which uses static content, like GIFs
and similar stuff, I have a slight problem. I would make source paths to such content in my
JSP file a relative one and my "web development tool" (Dreamweaver in this case) will place
them in the web-app directory. Upon deploying, I need to make copies to Apache's DocumentRoot

I know I can use Ant for this, but it requires a login to the server in question. Not to mention
that a configuration where Tomcat and Apache are not on the same host adds an additional layer
of "fun".

Is there a way to accopmlish upload and "division of static/dynamic" content autmagically?

> Now, if you configure Apache so that the directory being served by the
> "/foo" request URI prefix is the same as the directory defined as the
> context root of the "/foo" web app in Tomcat, you've accomplished the goal
> -- Tomcat serves all the requests that Apache forwards to it, and Apache
> serves all the requests that it doesn't forward.  But your application
> code is identical in either case.

Yes, it's the uploading that worries my, not to mention packaging? Is ther a way to make *one*
WAR that would deploy itself both to static and dynamic paths? Hmm, I don't think so, but
a build.xml that would take a few parameters should do the trick...

> Keep in mind that the ACTUAL directory pathname of your webapp doesn't
> need to have anything at all to do with the "/foo" prefix on requiest
> URIs.  Both Apache (via the "Alias" directive) and Tomcat (via the
> "docBase" attribute of the <Context> element) let you map that prefix to
> whatever real directory you want -- the secret is to make sure they both
> point at the same place.
> Lastly, I want to emphasize again, NONE of this is new to mod_webapp --
> the mod_jserv and mod_jk connectors have worked this way for around five
> years.  The only new thing mod_webapp was supposed to bring to the table
> was automatic configuration of the httpd.conf directives that make all of
> this happen, instead of requiring the sysadmin to do it all yourself.

I wish it was someplace in capital letters, saying "Dear newbie, this is the way we would
recomend doing Tomcat/Apache setup...".

View raw message