...
To configure a virtual host in Geronimo you basically need to:
Table of Contents | ||
---|---|---|
|
This article used the simple HelloWorld application as a reference, this application is covered in the Quick start - Apache Geronimo for the impatient section.
...
Now you need to define those virtual hosts in Geronimo's config.xml
so it can recognize them. This section provides two different virtual hosts definitions, that is creating two new HostGBean ( TomcatVirtualHost1 and TomcatVirtualHost2 ) in the Geronimo configuration, one of those 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.1/car">
. This is the beginning of the Tomcat configuration module, 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.1/car">
.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
...
<gbean gbeanInfo="org.apache.geronimo.tomcat.HostGBean"
name="org.apache.geronimo.configs/tomcat6/2.1/car?ServiceModule=org.apache.geronimo.configs/tomcat6/2.1/car,j2eeType=Host,name=TomcatVirtualHost_1">
<attribute name="className">org.apache.catalina.core.StandardHost</attribute>
<attribute name="initParams">name=virtualhost1.com
appBase=
workDir=work</attribute>
</gbean>
...
|
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.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
... <gbean gbeanInfo="org.apache.geronimo.tomcat.HostGBean" name="org.apache.geronimo.configs/tomcat6/2.1/car?ServiceModule=org.apache.geronimo.configs/tomcat6/2.1/car,j2eeType=Host,name=TomcatVirtualHost_2"> <attribute name="className">org.apache.catalina.core.StandardHost</attribute> <attribute name="initParams">name=virtualhost2.com appBase= workDir=work</attribute> <attribute name="aliases">virtualhost3.com,virtualhost4.com</attribute> </gbean> ... |
...
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
.
...
We will use the same application in both cases but will 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.
...
No Format | ||
---|---|---|
| ||
<app<APP_home>HOME>\ + HelloWorld.jsp + WEB-INF\ + geronimo-web.xml + web.xml |
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 on, in this case virtualhost1.com
.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.2"> <environment> <moduleId> <groupId>sample.applications</groupId> <artifactId>HelloWorldApp_1</artifactId> <version>2.1</version> <type>war</type> </moduleId> </environment> <context-root>/hello_1</context-root> <host>virtualhost1.com</host> </web-app> |
Save the changed to the geronimo-web.xml
file and generate a WAR file by typing the following command from the <app<APP_
home> HOME>
directory:
jar -cvf HelloWorld_1.war *
...
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
<artifactId>, context<context-rootroot> and host
<host>.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.2"> <environment> <moduleId> <groupId>sample.applications</groupId> <artifactId>HelloWorldApp_2</artifactId> <version>2.1</version> <type>war</type> </moduleId> </environment> <context-root>/hello_2</context-root> <host>virtualhost2.com</host> </web-app> |
Save the changed to the geronimo-web.xml
file and generate a second WAR file by typing the following command from the <app<APP_
home> HOME>
directory:
jar -cvf HelloWorld_2.war *
...
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<GERONIMO_
home>HOME>\bin
directory:
deploy --user system --password manager deploy <app<APP_home>HOME>\HelloWorld_1.war
You should get a successful confirmation message similar to this one:
No Format bgColor #000000 borderStyle solid
D:\geronimo-tomcat6-jee5-2.1\bin>deploy --user system --password manager deploy \HelloWorld_2.1\HelloWorld_1.war
Using GERONIMO_BASE: D:\geronimo-tomcat6-jee5-2.1
Using GERONIMO_HOME: D:\geronimo-tomcat6-jee5-2.1
Using GERONIMO_TMPDIR: var\temp
Using JRE_HOME: C:\Java\jdk1.5.0_06\jre
Deployed sample.applications/HelloWorldApp_1/2.1/war @
/hello_1
...
deploy --user system --password manager deploy <app<APP_home>HOME>\HelloWorld_2.war
You should get a successful confirmation message similar to this one:
No Format bgColor #000000 borderStyle solid
D:\geronimo-tomcat6-jee5-2.1\bin>deploy --user system --password manager deploy \HelloWorld_2.1\HelloWorld_2.war
Using GERONIMO_BASE: D:\geronimo-tomcat6-jee5-2.1
Using GERONIMO_HOME: D:\geronimo-tomcat6-jee5-2.1
Using GERONIMO_TMPDIR: var\temp
Using JRE_HOME: C:\Java\jdk1.5.0_06\jre
Deployed sample.applications/HelloWorldApp_2/2.1/war @
/hello_2
...