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

...

anchortoptop

This article shows how to configure Virtual Hosts in Apache Geronimo with Tomcat. By default, when you deploy and start an application in Geronimo, that application will be listeting listening on every available host name. By configuring a virtual host you can make an application to listen on a specific host name or IP. The configuration steps described in this article are also valid then when you are sharing a single IP among several host names.

To configure a virtal virtual host is in Geronimo you basically need to:

...

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 own way to define a local host table. For example Windows will have %SystemRoot%\system32\drivers\etc\hosts, Unix UNIX based operating systems would normally have an /etc/hosts.

For this example we will be using the following host names defines defined in the local host table:

127.0.0.1 localhost virtualhost1.com virtualhost2.com virtualhost3.com 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/tomcat/1.12/car">. This is the beginning of the Tomcat configuration module, all the additional virtual host configuration will be done immediatly immediately after this line.

To define the first HostGBean TomcatVirtualHost_1 add the following lines right after <module name="org.apache.geronimo.configs/tomcat/1.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 the entire config.xml with the two HostGBean already defined.

...

Back to Top

Declare the virtual host in the deployment plan

As mentioned before, for this example we are using the HelloWorld sample application covered in the Quick start - Apache Geronimo for the impatient section. Since this is a Web application, the deployment plan that we are modifying is the geronimo-web.xml. If you use a different type of application you may need to modify a different deployment plan, for example geronimo-application.xml. Refer to Deployment plans for further details.

...

We will use the same application in both cases but will differenciate differentiate one deployment from the other by giving it a different artifactId, this way we avoid modifying the code but still can identify each deployment.

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-app section add the host attribute and specify the Virtual Host you want this application to listen, 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:

...

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:

...

At this point you have configured Geronimo to use two different Virtual Hosts, one of them is also configured to listen under additional aliases. All you need to do now is to deploy the applications and test them. To deploy the applications type the following commands from the <geronimo_home>\bin directory::

deploy --user system --password manager deploy <app_home>\HelloWorld_1.war

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

#000000solid D:\geronimo-tomcat-j2ee-1.2\bin>deploy java -jar deployer.jar --user system --password manager deploy <app_home>\VH-sample-Tomcat\HelloWorld_1.2\HelloWorld_1.war

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

No Format

bgColor#000000
borderStylesolid
Using GERONIMO_BASE: D:\geronimo-tomcat-j2ee-1.2 Using GERONIMO_HOME: D:\geronimo-tomcat-j2ee-1.1\bin>java -jar deployer.jar --user system --password manager deploy \000-VH-sample\HelloWorld-VH\HelloWorld_1.war Deployed 2 Using GERONIMO_TMPDIR: D:\geronimo-tomcat-j2ee-1.2\var\temp Using JRE_HOME: C:\Java\jdk1.5.0_06\\jre Deployed sample.applications/HelloWorldApp_1/1.12/war @ http://hcunico:8080/hello_1

Note that the deployer tool will not tell the Virtual Host where the application was deployed to, it will only tell the machine's defined host name. If you try to access that URL you should get a HTTP Status 404 - /hello_1, resource not available. That error message is a good sign since we deployed the application to a particular Virtual Host.

...

java -jar deployer.jar --user system --password manager deploy <app_home>\HelloWorld_2.war

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

#000000solid D:\geronimo-tomcat-j2ee-1.2\bin>deploy --user system --password manager deploy \VH-sample-Tomcat\HelloWorld_1.2\HelloWorld_2.war Using GERONIMO_BASE: D:\geronimo-tomcat-j2ee-1.2 Using GERONIMO_HOME: D:\geronimo-tomcat-j2ee-1.2 Using GERONIMO_TMPDIR: D:\geronimo-tomcat-j2ee-1.2\var\temp Using JRE_HOME: C:\Java\jdk1.5.0_06\\jre Deployed No Format

bgColor#000000
borderStylesolid
D:\geronimo-1.1\bin>java -jar deployer.jar --user system --password manager deploy \000-VH-sample\HelloWorld-VH\HelloWorld_2.war Deployed sample.applications/HelloWorldApp_2/1.12/war @ http://hcunico:8080/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:

Host name / Virtual Host

Access

http://hcunico:8080/hello_1Image Removed

Fail

http://localhost:8080/hello_1Image Removed

Fail

http://virtualhost1.com:8080/hello_1Image Removed

SUCCESS!!!

http://virtualhost2.com:8080/hello_1Image Removed

Fail

http://virtualhost3.com:8080/hello_1Image Removed

Fail

http://virtualhost4.com:8080/hello_1Image Removed

Fail

Now repeat the tests for hello_2.

Host name / Virtual Host

Access

http://hcunico:8080/hello_2Image Removed

Fail

http://localhost:8080/hello_2Image Removed

Fail

http://virtualhost1.com:8080/hello_2Image Removed

Fail

http://virtualhost2.com:8080/hello_2Image Removed

SUCCESS!!!

http://virtualhost3.com:8080/hello_2Image Removed

SUCCESS!!!

http://virtualhost4.com:8080/hello_2Image Removed

SUCCESS!!!

Congratulations!!! you have successfully configured and deployed two applications to two different virtual hosts and aliases.

...