Sunday, 20 March 2016

How do you create multiple virtual hosts ?


If you want tomcat to accept requests for different hosts e.g., www.myhostname.com then you must : 

1. create ${catalina.home}/www/appBase , ${catalina.home}/www/deploy, and ${catalina.home}/conf/Catalina/www.myhostname.com

2. add a host entry in the server.xml file
  <Host appBase="http://www/appBase" name="www.myhostname.com"/>

3. Create the the following file under conf/Catalina/www.myhostname.com/ROOT.xml
  <?xml version="1.0" encoding="UTF-8"?>
  <Context path="/" docBase="http://www/deploy/mywebapp.war"  
    reloadable="true" antiJARLocking="true">
  </Context>
Add any parameters specific to this hosts webapp to this context file.

4. Put your war file in ${catalina.home}/www/deploy
    When tomcat starts, it finds the host entry, then looks for any context filesand will start any apps with a context.
    To add more sites just repeat and rinse, all webapps can share the same war file location and appbase.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.