Joe Hansen wrote:
Many Thanks for the link Chuck! Here's what I did.

1. Created a directory named c:\Tomcat\abc\ROOT.
2. Moved the previous contents of c:\Tomcat\webapps\abc to
c:\Tomcat\abc\ROOT directory.
...

Let me throw in my grain of salt.
I like things organised in a logical way, with a structure that immediately makes it clear to anyone what one is trying to achieve. And I like to have things that are logically at the same level, to also look that way at the physical level if possible.
Your mileage may vary as they say, but I would do as follows :

The basic Tomcat, which as downloaded and installed from the one and only original and genuine site, is structured as follows :

C:/tomcat : top installation dir   (*)
  |
  --- bin : the programs
  --- conf : the configuration files
  --- lib : common things
  --- webapps : standard and example applications
                + maybe your applications
          |
          --- ROOT : the standard default application
  --- etc..

Nice, clear, clean, matches the documentation etc..

In your server.xml, there is a single <Host> defined, it answers to the name "localhost", and it is also the default host, which means that if some DNS hostname evaluates to the IP address of your host computer, then any request addressed to that DNS hostname will be processed according to the setup of that <Host>.

To indicate that the web applications for that host live under c:/tomcat/webapps, there is the "appBase" attribute of the <Host> tag :
<Host name="localhost" appBase="webapps">
"webapps" being relative and thus interpreted as a subdirectory of the tomcat running directory, or CATALINA_BASE, which itself by default is the same as CATALINA_HOME, which is the tomcat installation directory c:/tomcat.

Now you add two web applications "abc" and "xyz".
The normal place would be to install these under c:/tomcat/webapps/abc and c:/tomcat/webapps/xyz.
But then, you would have to access them via URLs like
http://hostname:port/abc
http://hostname:port/xyz

Instead, you would like to access them as respectively
http://abc.local/
http://xyz.local

That requires 2 parts :

1) you have to make abc.local and xyz.local into DNS aliases evaluating to the same IP address as your physical host.
That, you did already, in part.

2) you have to make each of these applications be the "default application", so that you can call them without the prefix (abc or xyz).
That is a problem, because
  - there is already a ROOT application (the default Tomcat one)
  - abc and xyz cannot be both renamed to ROOT
So you decide to solve this by using virtual hosts.
Very good, that is one of the ways.

So we add 2 virtual host declarations to the Tomcat server.xml, for a total of 3 :
   <Host name"localhost" appBase="webapps">
...
   <Host name"abc.local" appBase="webapps-abc">
...
   <Host name=xyz.local" appBase="webapps-xyz">

and we change our basic directory layout to be :

C:/tomcat : top installation dir
  |
  --- bin : the programs
  --- conf : the configuration files
  --- lib : common things
  --- webapps : standard and example applications
                + maybe some of your applications
          |
          --- ROOT : the standard default application
  --- webapps-abc : the applications of the "abc.local" host
          |
          |-- ROOT : the default application of the abc.local host
  --- webapps-xyz : the applications of the "xyz.local" host
          |
          |-- ROOT : the default application of the xyz.local host
  --- etc..

This way, you get to keep the standard and example applications of the original Tomcat, to test and play around with. These will be called whenever there is a request to
http://localhost/
http://127.0.0.1/
http://anything/
as long as "anything" evaluates to one of the IP addresses of your physical host, and there is no specific <Host name="anything"> defined. And whenever someone uses one of the names defined in a <Host> tag, they will be directed to the corresponding appBase applications. Also, the appBase's do not overlap, and they are at the same level in the file hierarchy, which is easy to understand, conveys well the idea that they are two choices at the same level, simplifies permission settings, is easy for backups etc..

There are other techniques and layouts possible to achieve the same effect, but I would not in any case base one application under tomcat_dir/abc
and another one under
tomcat_dir/webapps/xyz
because I would find that confusing, and because I would not want the future Tomcat developers of version 9.3 to suddenly find that "abc" or "xyz" would be a cute name for a future indispensable Tomcat subdirectory to store whatever. I would also not want my boss to get the idea that the real nice name for application "abc" should really be "server", and make things really messy.


(*) In fact, it isn't. It normally wants to install itself in some awfully chosen directory with plenty of spaces in the name, guaranteed to give you stomac acidity some day, so don't let it do that.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to