How to proxy various WAR in Tomcat 7?

I am developing a web application consisting of two independent parts - authentication and the real part of the application. Both parts of the WAR that are deployed to (currently) a single instance of Tomcat 7.

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

 webapps | +- BloggofantAuthentication | +- Bloggofant 

so far they are available at http://127.0.0.1:8080/BloggofanAuthentication and http://127.0.0.1:8080/Bloggofant . Is it possible to proxy WAR in Tomcat directly (so I do not need to use Apache httpd and its mod_proxy module)? So in the end, a WAR on the server is achievable as follows:

  • http://127.0.0.1:8080/BloggofantAuthenticationhttp://127.0.0.1/bloggo/
  • http://127.0.0.1:8080/Bloggofanthttp://127.0.0.1/bloggo/fant/

Any suggestions on this topic are much appreciated;)

EDIT

The following are the context.xml files for the two unpacked WARUP folders for Webapp:

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 now I want to access my applications through http://127.0.0.1:8080 or http://127.0.0.1:8080/Bloggofant , I get 404 error - Page not found ...

+6
source share
1 answer

You can configure the path where Tomcat serves the web application using the context.xml file . You can put this in the WAR META-INF directory with the contents:

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

And he will serve it there, not the default /Bloggofant .

Note the warning about automatic deployment in the documentation:

When the autoDeploy or deployOnStartup operations are performed by the host, the name and context path of the web application are performed on behalf of the file (s) that define the web application (s). Therefore, the context path cannot be defined in META-INF / context.xml embedded in the application

Elsewhere, the documentation tells us that both defaults are true . Therefore, you need to set them to false so that these parameters are respected.

+3
source

Source: https://habr.com/ru/post/956651/


All Articles