-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Tony,

On 10/21/2009 2:11 PM, Tony Anecito wrote:
> How would one associate the static content within a WAR with a
> subdomain when using subdomains assigned to directories?

Perhaps your (clarified) question really is:

Can I deploy only the static-content portions of my webapp to multiple
virtual hosts whilst deploying my dynamic-content portions only on a
single host?

If that's your question, then the answer is "yes, but why?".

Tomcat, like Apache httpd, has the notion of the default virtual host.
In Tomcat, the <Engine> element in server.xml specifies the hostname for
the <Host> that should be considered the default (that is, the one
handling requests for any hostnames that don't match any /other/ defined
<Hosts> or their <Alias>es). Got all that?

If you want to serve your webapp on www.foo.com, all you need is:

<Engine name="Catalina" defaultHost="www.foo.com">
   <Host name="www.foo.com" ...
   ...
</Engine>

Or even:

<Engine name="Catalina" defaultHost="localhost">
   <Host name="localhost" ...
   ...
</Engine>

I prefer the second one, because a) it comes like that directly from the
Tomcat builds and b) you won't confuse yourself by setting lots of
hostname-specific stuff that you just don't need. If you have a more
complex configuration and requirements, then, by all means change the
defaultHost and add more <Host elements. But only do it if you really
need them.

So, back to your question, as re-phrased by me. If you want to, say,
optimize your website's loading speed because your clients will only
make 2 connections to www.foo.com, by adding images.foo.com,
images2.foo.com, and images3.foo.com, you can rest assured that, as long
as your DNS entries deliver the HTTP requests to your Tomcat server one
way or another, the static content will be returned to the client
without one single change to the configuration above.

If you /really/ want your webapp to be available /only/ on www.foo.com
(and neither images.foo.com, nor images2.foo.com, etc.) then you have
one of two options:

1. Write a filter that rejects all requests that aren't coming from
www.foo.com and are requesting dynamic resources (you'd do this by only
mapping the filter to, say, *.jsp and other similar URL patterns).

2. Configure multiple hosts, like this:

<Engine name="Catalina" defaultHost="localhost">
   <Host name="www.foo.com" appBase="webapps" ...
      ...
   </Host>

   <Host name="localhost" appBase="static-files" ...
      ...
   </Host>
</Engine>

Now, only requests to www.foo.com will get to your "real" webapps, while
requests to any other domain name (you don't even have to configure
them: they all magically work) will go to the static-files directory
(note that you'll need your files in a directory something like
..../static-files/ROOT or ..../static-files/myWebAppName in order for
the files to actually be found: this should match the context name of
your actual webapp(s)).

I hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrfZv8ACgkQ9CaO5/Lv0PCilQCfd9T17lJXoW76pKgkka3q0Zws
mVcAn0oSzwauU0n6sZ/OoKlp0U7JjK9o
=GjFu
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to