Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat: Defining a Context, what are [Enginename] and [Hostname]?

Tags:

tomcat

In the documentation of Tomcat, the section about Defining a context lists the following options to define a context:

  1. In an individual file at /META-INF/context.xml inside the application files.
  2. In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The context path and version will be derived from the base name of the file (the file name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.
  3. Inside a Host element in the main conf/server.xml.

Option 1 is bad, because it means that one must hard code the values inside the application artifact and they cannot be easily changed.

Option 3 is actively discouraged by the documentation:

It is NOT recommended to place elements directly in the server.xml file.

This only leaves us with option 2, especially this is the only option if we would like to deploy the same application several times with different configurations (e.g. one for production, one for testing).

However the documentation does not explain, what [enginename] or [hostname] are supposed to be, or what they default to.

What are the default values for these and where can I change them?

like image 272
lanoxx Avatar asked May 25 '17 12:05

lanoxx


1 Answers

TL;DR [enginename] is usually Catalina and [hostname] is usually localhost.

Simple Explanation

In the default configuration that is shipped with Tomcat, the engine is configured in $CATALINA_HOME/conf/server.xml, at the end of that file you will usually see something like this:

<Engine name="Catalina" defaultHost="localhost">

    ...         

    <Host name="localhost"  appBase="webapps"
          unpackWARs="true" autoDeploy="true">
</Engine>

The name property of <Engine> element is the enginename and the name property of the <Host> element is the hostname.

Longer Explanation

The answer can be found in two places, by reading the Host and Engine pages of the Tomcat documentation.

For the <Engine> element the interesting values are:

defaultHost:

The default host name, which identifies the Host that will process requests directed to host names on this server, but which are not configured in this configuration file. This name MUST match the name attributes of one of the Host elements nested immediately inside.

name:

Logical name of this Engine, used in log and error messages. When using multiple Service elements in the same Server, each Engine MUST be assigned a unique name.

For the <Host> element it states:

name:

Usually the network name of this virtual host, as registered in your Domain Name Service server. Regardless of the case used to specify the host name, Tomcat will convert it to lower case internally. One of the Hosts nested within an Engine MUST have a name that matches the defaultHost setting for that Engine. See Host Name Aliases for information on how to assign more than one network name to the same virtual host.

like image 186
lanoxx Avatar answered Sep 21 '22 13:09

lanoxx