开发者

Can we point multiple urls to the same webapp in tomcat

I am using an apache web server and a tomcat server for hosting few webapplications.

These webapplications not very different from one another and I want to consolidate all these webapplications into one webapp to minimize the process overheads.

The w开发者_Python百科ebapplications are currently being accessed with separate urls ex: localhost:8080/webapp1, localhost:8080/webapp2.

Without changing the urls is there a way that I can host a webapplication on tomcat say "singlewebapp" such that it will respond to both localhost:8080/webapp1 as well as localhost:8080/webapp2?


One of my team members suggested an idea on symlinks and junctions which triggered a discussion on apache tomcat's docbase feature and we found a very elegant answer to this question in it.

Let's say the webapplication is abc.war. We deploy abc.war in tomcat webapps as abc folder then we need to configure the server.xml of tomcat as follows and restart tomcat:

<Host ...>
  ...
  <Context path="/webapp1" docBase="/abc" /> 
  <Context path="/webapp2" docBase="/abc" /> 
</Host>

Believe this is very useful usage for supporting white-labelling and multi-tenancy.


I dont think you can do this in that way. Looks like your host name and ports for all the applications are same, but context roots (webapp1 and webapp2) are different. We cannot have sinlgle context root to access myltiple applications with same host name and port.

Every web server can run one application on one port and host combination. If you want to run multiple applications on the same host, obviously you need to add as many virtual IPs and should be configured in your web server .config file to make the applications accessible virtually.

We can create virtual servers on web server based on IP address ( there are software and hardware virtual server concepts which you need to study). To have multiple IP address on your single server you need add as many ethernet cards to expand the number of IPs virtually.

If you fine to use virtual server concept , offcourse you need slightly change your requirement.


Instead of editing server.xml make context.xml in local host(or your host) of catalina of tomcat. because if edit server.xml we need to restart the server.

creation of context.xml :

  1. xml file name must be your path name i,e webapp1/webapp2

  2. data in xml as follows (if you are creating path for abc.war file)

    a). xml file name is webapp1.xml b). xml file name is webapp2.xml

    "lessthan symbol" ?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    "lessthan symbol" Context reloadable="true" privileged="true" docBase="${catalina.home}/abc" crossContext="true" antiResourceLocking="false" allowLinks="true"/>
    

above xml files must be place in tomacat/conf/Catalina//

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜