Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you map a sub domain to a webapp on Tomcat 6 (including the root webapp)?

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?

like image 205
Kawu Avatar asked Sep 14 '10 10:09

Kawu


People also ask

How do I map a domain in Tomcat web application?

Step 1: Open file server. xml in folder C:/Tomcat7. 2/conf. Step 3: Save file and restart apache tomcat.

What is webapp folder in Tomcat?

The webapps directory is where deployed applications reside in Tomcat. The webapps directory is the default deployment location, but this can be configured with the appBase attribute on the <Host> element.


1 Answers

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>
like image 50
JoseK Avatar answered Oct 23 '22 10:10

JoseK