views:

115

answers:

1

Hello,

subject says it all. What I want is to map each sub domain to a webapp like:

http://root.domain.com:8080 -> http://domain.com:8080/
http://manager.domain.com:8080 -> http://domain.com:8080/manager
http://abc.domain.com:8080 -> http://domain.com:8080/abc
http://def.domain.com:8080 -> http://domain.com:8080/def

on a localhost machine this would be

http://root.localhost:8080 -> http://localhost:8080/
http://manager.localhost:8080 -> http://localhost:8080/manager
http://abc.localhost:8080 -> http://localhost:8080/abc
http://def.localhost:8080 -> http://localhost:8080/def

Ideally, I'd like to use port 80 instead of 8080, but that's another story. I'd be happy to get it going with port 8080 at first, so that the path at the end of the URL disappears.

Note, the arrows aren't redirects but what I'd enter if I left Tomcat as is.

I know the Tomcat docs page http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html. I've read it many times, but didn't make much progress. I edited etc/hosts to add 127.0.0.1 bbstats.localhost. I then added

<Host name="bbstats.localhost" appBase="webapps/bbstats"
      unpackWARs="true" autoDeploy="true"
      xmlValidation="false" xmlNamespaceAware="false">
</Host>

to Tomcat's server.xml in the conf dir. My webapp's context.xml is:

<Context path="/bbstats" docBase="bbstats" debug="5" reloadable="true" crossContext="true"> 
</Context>

Restart Tomcat. Redploy via Ant. When entering

http://bbstats.localhost:8080/

into a browser, I get a blank screen.

When using appBase="webapps" instead of appBase="webapps/bbstats", I get to Tomcat's root app. The latter behavior is kind of expected. But how do I make bbstats.localhost:8080 go to the bbstats webapp without a trailing /bbstats in the URL?

Karsten

+2  A: 

Can you try nesting each web app as the root webapp within the <Host> in server.xml by giving path="". I havent tried this myself.

 <Host name="bbstats.localhost" appBase="webapps">
    <Context path="" docBase="/bbstats/"/>
      </Host>

      <Host name="tomcatstuff.localhost" appBase="webapps">
    <Context path="" docBase="/tomcatstuff/"/>
      </Host>
JoseK
I'm now using "<Context path="" docBase="/bbstats"/>" and it works now! :-) Note I've also removed path and docBase from my META-INF/context.xml. Quoting http://old.nabble.com/appbase-and-docbase-td18616249.html: "...the path and docBase attributes are not allowed for a <Context> element in META-INF/context.xml" I further found your technique confirmed by http://oreilly.com/java/archive/tomcat-tips.html. Cheers!
Kawu