Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make the URL without the "webapp"

 
Kevin Kan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have integrated Apache2 with Tomcat7. I have also deployed my webapp "app1" in the "webapps" folder. I can access my "app1" successfully at http://app1.domain.com/app1/index.jsp.

However, I am wondering how can I further achieve the same without including the in the URL?
Ie. Currently I am accessing the application at http://app1.domain.com/app1/index.jsp. How can I access the application at http://app1.domain.com/index.jsp?

Thanks in advance!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat convention uses the app residing in the ROOT directory for that URL - just replace the contents of ROOT with your app.

Bill
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EVERY Tomcat webapp has a "webapp" component to its URL. Or "context", as it's properly known. That's because Tomcat is a multi-application container, and the context servers as an indicator to Tomcat as to which of the applications it contains a given URL should be routed to. Context paths are simply 0 or more "directory levels" in the URL.

As William has said, there's a special context whose path is "/", meaning no levels at all and that's the root context. It's a little bit trickier to deploy than the others, since Tomcat is shipped with a root context already installed, so you have to replace it with your own app.

However, when you're fronting Tomcat with Apache, this isn't really necessary. You can use a "normal" context path in Tomcat and let Apache handle the difference. Typically, you'd define an Apache Virtual Host such as "app1.domain.com" and within the virtual host definition you'd provide the connector to Tomcat for that virtual host using either the traditional connector or a mod_proxy connector. Part of that connector's definition would include the actual Tomcat context path in the translated URL, so that the user could use the simpler URL but Apache would route it to the proper context.

Here's an example of how it works using mod_proxy and a deployed webapp under the context name "WMS-tomcat".

 
Kevin Kan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Thanks for your replies.

To William:
I've tried replacing the default 'ROOT' folder with my 'app1' folder and it worked like a charm!

To Tim:
I have mod_jk installed and was trying out your "proxy method" and is trying to confirm the changes required.
Below is my virtual host configuration for my subdomain:



Is this what you meant to reconfigure in Apache, in order to achieve the same result?
Thanks in advance!

Cheers!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic