Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to proxy different WARs in Tomcat 7?

I'm developing a web application, which consists of two independent parts - the authentication and the real application part. Both parts are WARs which are deployed at (currently) one Tomcat 7 instance.

So, I have the following two WARs in my webapps folder:

webapps
|
+- BloggofantAuthentication
|
+- Bloggofant

until now they are available at http://127.0.0.1:8080/BloggofanAuthentication and http://127.0.0.1:8080/Bloggofant. Is it possible proxy the WARs at Tomcat directly (so that I don't have to use Apache httpd and its mod_proxy module)? So that in the end, the WARs at the server are reachable as follows:

  • http://127.0.0.1:8080/BloggofantAuthentication --> http://127.0.0.1/bloggo/
  • http://127.0.0.1:8080/Bloggofant --> http://127.0.0.1/bloggo/fant/

Any suggestions on this topic are highly appreciated ;)

EDIT

Here are the context.xml files of the two unpacked webapp WAR folders:

webapps/BloggofantAuthentication/META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context path="">
    <!-- Comment this to enable session persistence across Tomcat restarts -->
    <Manager pathname=""/>
</Context>

webapps/Bloggofant/META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/bloggofant">
    <!-- Comment this to enable session persistence across Tomcat restarts -->
    <Manager pathname=""/>
</Context>

If I now want to access my apps via http://127.0.0.1:8080 or http://127.0.0.1:8080/bloggofant I get a 404 - Page Not Found error ...

like image 651
herom Avatar asked Oct 24 '13 13:10

herom


People also ask

Can we deploy WAR file in Tomcat?

Perhaps the simplest way to deploy a WAR file to Tomcat is to copy the file to Tomcat's webapps directory. Copy and paste WAR files into Tomcat's webapps directory to deploy them. Tomcat monitors this webapps directory for changes, and if it finds a new file there, it will attempt to deploy it.

What is webapps 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.

How do I know if war is deployed in Tomcat?

The definitive way to determine if a war has finished deploying and the webapp has started is to look in the catalina. out log. A message will be logged. In operational terms, Tomcat will respond to a request made to that webapp in various ways depending on how far along it is.

How many ways we can deploy the application into Tomcat?

As we can see, there are two ways for deploying a web application using the manager: Deploy directory or WAR file located on server. WAR file to deploy.


1 Answers

You can configure the path at which Tomcat serves a web application using a context.xml file. You can put this in the WAR's META-INF directory, with the content:

<Context path="/bloggo/fant" />

And it will serve it there instead of at the default /Bloggofant path.

Note the warning about automatic deployment in the documentation:

When autoDeploy or deployOnStartup operations are performed by a Host, the name and context path of the web application are derived from the name(s) of the file(s) that define(s) the web application. Consequently, the context path may not be defined in a META-INF/context.xml embedded in the application

Elsewhere, the documentation tells us that these both default to true. Thus, you will need to set them to false for these settings to be respected.

like image 142
Tom Anderson Avatar answered Oct 28 '22 16:10

Tom Anderson