How to setup a tomcat virtualhost without webapps?

18,114

Solution 1

To point to your own directory try the following:

go to the tomcat folder %path_to_tomcat%/conf/Catalina/localhost You can also change localhost to your host if you want, but if the only thing you are trying to do is get your app on '/' then localhost is fine.

create a file called ROOT.xml in the previously defined folder. In that file add the following

<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="/home/destiny/www">
</Context>

Also look in %path_to_tomcat%/webapps/, and delete/move/rename the ROOT folder that is there if you don't want the default tomcat page to be there.

See the approach #2 @ this link for more details.

Solution 2

This works for me in Tomcat 7:

<Host name="myhost.com" appBase="">
  <Context path="/" docBase="/home/destiny/www"/>
</Host>

It's probably not the best way to configure Tomcat but it gets a webapp working quickly.

Solution 3

This is sort of an old thread but I wanted to share my experience since this came up in my search results. My issue was upgrading old JSP apps that were exploded in a file structure containing subdirectories on a new server that was using cPanel and an easy tomcat 7 install. Files in subdirectories were not able to reference included files in other directories. Essentially Tomcat was creating a separate context for each subdirectory then I was getting lots of file not found errors on includes.

So I did what Mark suggested with a bit of a change. My server was setup with each virtual host's web document root set to /home/domainuser/public_html and the default tomcat server.xml was setting both the appbase and the context docbase to that directory.

So what finally worked was to "split" up the directory path and put part as the appbase, and then the docbase for my context as the public_html directory. See the example below.

    <Host name="domain.com" appBase="/home/domainuser/" unpackWARs="false" deployXML="false">
      <Alias>www.domain.com</Alias>
      <Context path="" reloadable="true" docBase="public_html" debug="1"/>
   </Host>
Share:
18,114
smallufo
Author by

smallufo

A Java/Kotlin programmer twitter : http://twitter.com/smallufo

Updated on June 27, 2022

Comments

  • smallufo
    smallufo almost 2 years

    I am trying to migrate my webapp from resin to Tomcat7 . One thing confuses me is I don't know how to setup a 'default' webapp for one virtual host ?

    That is , my site has just one app : "/" , located in "/home/destiny/www" . There are many PHP scripts inside (served by apache) , and one WEB-INF directory inside , with a standard JavaEE app. My app is not packaged in WAR , it is default expanded.

    I try to find documents about how to setup a virtual host in tomcat 7 , but all examples need a 'webapps' directory for WARs to expand , but that's not my case !

    Here is my server.xml settings (tomcat 7.0.23 ) :

    <Host name="myhost.com" xmlBase="/home/destiny/www" 
      unpackWARS="false" autoDeploy="true">
      <Context path="/" docBase="." />
    </Host>
    
    <!-- default tomcat's host -->
    <Host name="localhost"  appBase="webapps"
      unpackWARs="true" autoDeploy="true"> ... </Host>
    

    When I start tomcat , I see my webapp not loaded , only tomcat's webapps (host-manager , manager , examples , docs , ROOT ...) loaded. When I open my site , it shows tomcat's default screen (with broken images).

    The configuration is not working... ( I tried xmlBase , appBase , docBase ... but all in invain)

    It seems one solution is a webapp named 'ROOT' in /home/destiny/www/webapps/ROOT directory , but I don't want that solution ! I want my default web app in /home/destiny/www . and there'll be no other webapps installed (I don't need a webapps dir ).

    How to solve it (It's so easy to achieve in resin) ? Thanks.