I'm developing a web application, which consists of two independent parts - the authentication and the real application part. Both parts are WAR
s which are deployed at (currently) one Tomcat 7 instance.
So, I have the following two WAR
s 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 WAR
s at Tomcat directly (so that I don't have to use Apache httpd
and its mod_proxy
module)? So that in the end, the WAR
s 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 ;)
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 ...
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With