Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Wiki Markup{scrollbar}excerptINLINE

This article shows how to configure Virtual Hosts in Apache Geronimo with Tomcat.

...

...

This article used the simple HelloWorld application as a reference, this application is covered in the Quick start - Apache Geronimo for the impatient section.

...

To make this configuration work you need to ensure that Geronimo can resolve the virtual host name you are about to define. Depending on your network configuration you can add an entry to you DNS, an alias to the Geronimo server IP. Alternatively you can add an entry to the local host table, each operating system has it's its own way to define a local host table. For example Windows will have %SystemRoot%\system32\drivers\etc\hosts, UNIX based operating systems would normally have an /etc/hosts.

...

Now you need to define those virtual hosts in Geronimo's config.xml so it that Geronimo can recognize them. This section provides two different virtual hosts host definitions, that is creating two new HostGBean ( TomcatVirtualHost1 and TomcatVirtualHost2 ) in the Geronimo configuration, one of those which will have multiple host names aliases. The goal of this example is to have an application listening on a single virtual host ( this will be virtualhost1.com ) and another application listening on a different virtual host ( this will be virtualhost2.com ) with two additional aliases ( this will be virtualhost3.com and virtualhost4.com ).

Open the config.xml file located in the <geronimo_home>/var directory and look for the following line <module name="org.apache.geronimo.configs/tomcat6/2.12/car">. This is the beginning of the Tomcat configuration module, all . All the additional virtual host configuration will be done immediately after this line.

To define the first HostGBean TomcatVirtualHost_1 add the following lines right after <module name="org.apache.geronimo.configs/tomcat6/2.12/car">.

...

...

To add the second HostGBean TomcatVirtualHost_2 add the following lines right after the first HostGBean. These two HostGBeans have been split so it is easier to identify them. The main difference between these two is the <attribute name="aliases">..,..</attribute> line to define the aliases.

...

...

At this point you have successfully configured two different virtual hosts in Geronimo. Make sure you save the changes to the config.xml file and start Geronimo.

For additional reference, this is an excerpt from config.xml of the entire <module name="org.apache.geronimo.configs/tomcat6/2.12/car"> entry with the two HostGBean already defined.

...

...

Note: Some tags in the config.xml shown above are presented in multiple lines for displaying purposes only.

...

Assuming you followed the steps covered in the Quick start - Apache Geronimo for the impatient section you should have the following structure:

...

Open the geronimo-web.xml file and edit the artifactId and context-root to make this deployment unique. Within the web<web-appapp> section add the host attribute and specify the Virtual Host you want this application to listen on, in this case virtualhost1.com.

...

...

Save the changed to the geronimo-web.xml file and generate a WAR file by typing the following command from the <APP_HOME> directory:

{*}jar -cvf HelloWorld_1.war * *

Once deployed this application should only listed in the virtualhost1.com host name.

We will now repeat this steps to create a second WAR. Edit once again the geronimo-web.xml file and copy the content form the following example. Note that we are only changing the <artifactId>, <context-root> and <host>.

...

...

Save the changed to the geronimo-web.xml file and generate a second WAR file by typing the following command from the <APP_HOME> directory:

{*}jar -cvf HelloWorld_2.war* *

You now have two applications ready to be deployed to two different virtual hosts.

...

You should get a successful confirmation message similar to this one:

...

#000000

...

solid

...

D:\geronimo-tomcat6-jee5-2.

...

2\bin>deploy

...

--user

...

system

...

--password

...

manager

...

deploy

...

\HelloWorld_2.

...

2\HelloWorld_1.war

...

Using

...

GERONIMO_BASE:

...

D:\geronimo-tomcat6-jee5-2.

...

2 Using

...

GERONIMO_HOME

...

: D:\geronimo-tomcat6-jee5-2.

...

2 Using

...

GERONIMO_TMPDIR:

...

var\temp

...

Using

...

JRE_HOME:

...

C:\Java\jdk1.5.0_06\jre

...

Deployed

...

sample.applications/HelloWorldApp_1/2.

...

2/war

...

@

...

/hello_1

...

 

Repeat the deployment for the second application.

...

You should get a successful confirmation message similar to this one:

...

#000000

...

solid

...

D:\geronimo-tomcat6-jee5-2.

...

2\bin>deploy

...

--user

...

system

...

--password

...

manager

...

deploy

...

\HelloWorld_2.

...

2\HelloWorld_2.war

...

Using

...

GERONIMO_BASE:

...

D:\geronimo-tomcat6-jee5-2.

...

2 Using

...

GERONIMO_HOME:

...

D:\geronimo-tomcat6-jee5-2.

...

2 Using

...

GERONIMO_TMPDIR:

...

var\temp

...

Using

...

JRE_HOME:

...

C:\Java\jdk1.5.0_06\jre

...

Deployed

...

sample.applications/HelloWorldApp_2/2.

...

2/war

...

@

...

/hello_2

...

 

With the applications deployed the only thing left is to test them. Test hello_1 first, try to access the hosts names defined on the Geronimo server machine:

...