2009/11/23 Looijmans, Mike <mike.looijm...@oce.com>

> Hello,
>
> After hours of googling and browsing documentation, i came to the
> conclusion that what i want is either so trivial that everybody knows how to
> do it, or so complicated that no one ever tried it...
>
> I want to accomplish the following in Tomcat 5.5:
>
> http://myserver:80/xxx just does whatever it always does.
> http://myserver:666/xxx is equivalent to http://myserver:80/myapp/xxx
>
> So i want all requests targetted at a particular port (666) in this case to
> be forwarded to a particular servlet, which is also served under its own
> subdirectory on the regular HTTP port 80.
>
> I can set up a connector at port 666 and have all its request go somewhere
> else, but then the application cannot be reached through the normal port
> (80), which is crucial for this thing to work. Installing two copies will
> accomplish that, but then the two copies live in different universes and
> cannot communicate - and setting up some IPC between them is overkill i'd
> say.
>
> It's not at all obvious :-).  You can sort-of pick the bones out of
http://tomcat.apache.org/tomcat-5.5-doc/index.html , but unfortunately I've
always found the official Tomcat docs to be very short of worked examples.

Because you want different sets of webapps served on your different
connectors, I *think* you'll need two different Services in your server.xml:

<Server>
  <Service> for port 80
    <Connector> for port 80
    <Engine> for port 80
      <Host> for port 80, specifying base directory for your port 80 webapps
    </Engine> for port 80
  </Service> for port 80

  <Service> for port 666
    <Connector> for port 666
    <Engine> for port 666
      <Host> for port 666, specifying base directory for your port 666
webapps
    </Engine> for port 666
  </Service> for port 666
</Server>

The fastest way to make such a configuration will be to edit your existing
server.xml, copy+paste the <Service>...</Service> section (which is most of
the file) and hack at the copy as necessary.

Note that you'll end up with two independent copies of the servlet in your
two webapp directories, and they won't share things like Sessions between
them.  I can't think of a way of doing that using just Tomcat's features.
You might, however, be able to get what you want using a combination of
http://tuckey.org/urlrewrite/ and two Connectors defined on the same
Service.

Good luck!

- Peter

Reply via email to