Child pages
  • Configuring Virtual Host in Tomcat
Skip to end of metadata
Go to start of metadata

{scrollbar}INLINE

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 listening on every available host name. By configuring a virtual host, you can make an application listen on a specific host name or IP. The configuration steps described in this article are also valid when you are sharing a single IP among several host names.
To configure a virtual host in Geronimo, you basically need to do the following actions:

2

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

Configure local host or DNS

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 your DNS, or an alias to the Geronimo server IP. Alternatively, you can add an entry to the local host table. Each operating system has its own way to define a local host table. For example Windows will have %SystemRoot%\system32\drivers\etc\hosts, and UNIX based operating systems would normally have an /etc/hosts.

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

127.0.0.1 localhost virtualhost1.com virtualhost2.com virtualhost3.com virtualhost4.com

Make sure that your system can resolve these names.

Define Virtual host

There are three approaches to defining a virtual host in Geronimo:

  1. Manually by directly editing Geronimo's var/config/config.xml to set the definition. Requires a restart of Geronimo.
  2. Automatically by deploying a GBean which contains the definition. Does not require a restart of Geronimo.
  3. Manually by editing Tomcat Catalina's var/catalina/server.xml to set the definition. Requires a restart of Geronimo.

We will cover the first two options which are specific to Geronimo's methodology of configuration. Instructions on performing the third option can be found in documentation on the Apache Tomcat project web site.

Manually editing var/config/config.xml

Now you need to define those virtual hosts in Geronimo's config.xml file so that Geronimo can recognize them. This section provides two different virtual host definitions, one defined with multiple host names aliases and one without host names alias. The virtual hosts are defined by creating two new HostGBean ( TomcatVirtualHost1 and TomcatVirtualHost2 ) in the Geronimo configuration. The goal of this example is to have an application listen on a single virtual host ( virtualhost1.com ) and another application listen on a different virtual host ( virtualhost2.com ), which has two aliases ( 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/tomcat7/3.0/car">. This is the beginning of the Tomcat configuration module. All the additional virtual host configurations 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/tomcat7/3.0/car">.

xmlExcerpt from config.xmlsolid ... <gbean gbeanInfo="org.apache.geronimo.tomcat.HostGBean" name="org.apache.geronimo.configs/tomcat7/3.0/car?ServiceModule=org.apache.geronimo.configs/tomcat7/3.0/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> <reference name="Engine"> <pattern> <name>TomcatEngine</name> </pattern> </reference> </gbean> ...

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

xmlExcerpt from config.xmlsolid ... <gbean gbeanInfo="org.apache.geronimo.tomcat.HostGBean" name="org.apache.geronimo.configs/tomcat7/3.0/car?ServiceModule=org.apache.geronimo.configs/tomcat7/3.0/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> <reference name="Engine"> <pattern> <name>TomcatEngine</name> </pattern> </reference> </gbean> ...

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

For additional reference, see the following excerpt from config.xml of the entire <module name="org.apache.geronimo.configs/tomcat7/3.0/car"> entry with the two HostGBean already defined.

xmlconfig.xmlsolid <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <attributes xmlns:ns2="http://geronimo.apache.org/xml/ns/plugins-1.3" xmlns="http://geronimo.apache.org/xml/ns/attributes-1.2"> <comment> ================================================================== Warning - This XML file is regenerated by Geronimo whenever changes are made to Geronimo's configuration. If you want to include comments, create a single comment element element. They are allowable at any level of the configuration. !!!! Do not edit this file while Geronimo is running !!!! ==================================================================</comment> <module name="org.apache.geronimo.framework/j2ee-system/3.0-SNAPSHOT/car"/> <module load="false" name="org.apache.geronimo.framework/client-system/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.framework/rmi-naming/3.0-SNAPSHOT/car"> <gbean name="RMIRegistry"> <attribute name="port">${NamingPort + PortOffset}</attribute> <attribute name="host">${ServerHostname}</attribute> </gbean> <gbean name="DefaultThreadPool"> <attribute name="keepAliveTime">30000</attribute> <attribute name="minPoolSize">${MinThreadPoolSize}</attribute> <attribute name="maxPoolSize">${MaxThreadPoolSize}</attribute> </gbean> </module> <module name="org.apache.geronimo.framework/plugin/3.0-SNAPSHOT/car"> <gbean name="DownloadedPluginRepos"> <attribute name="repositoryList">http://geronimo.apache.org/plugins/plugin-repository-list-3.0.txt</attribute> </gbean> </module> <module name="org.apache.geronimo.framework/j2ee-security/3.0-SNAPSHOT/car"> <gbean name="JMXService"> <attribute name="protocol">rmi</attribute> <attribute name="host">${ServerHostname}</attribute> <attribute name="port">${JMXPort + PortOffset}</attribute> <attribute name="urlPath">/jndi/rmi://${ServerHostname}:${NamingPort + PortOffset}/JMXConnector</attribute> </gbean> </module> <module name="org.apache.geronimo.framework/server-security-config/3.0-SNAPSHOT/car"/> <module load="false" name="org.apache.geronimo.framework/shutdown/3.0-SNAPSHOT/car"/> <module load="false" name="org.apache.geronimo.framework/online-deployer/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.framework/bundle-recorder/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.framework/geronimo-gbean-deployer/3.0-SNAPSHOT/car"> <gbean name="Deployer"> <attribute name="remoteDeployAddress">http://${RemoteDeployHostname}:${HTTPPort + PortOffset}</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/j2ee-server/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/j2ee-deployer/3.0-SNAPSHOT/car"> <gbean name="WebBuilder"> <attribute name="defaultNamespace">http://geronimo.apache.org/xml/ns/j2ee/web/jetty-2.0</attribute> </gbean> <gbean name="EnvironmentEntryBuilder"> <attribute name="eeNamespaces">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/bval-deployer/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/transaction-1_6/3.0-SNAPSHOT/car"> <gbean name="XidFactory"> <attribute name="tmId">${TmId}</attribute> </gbean> <gbean name="ResourceBindings"> <attribute name="format">${ResourceBindingsFormat}</attribute> <attribute name="nameInNamespace">${ResourceBindingsNameInNamespace}</attribute> <attribute name="namePattern">${ResourceBindingsNamePattern}</attribute> <attribute name="abstractNameQuery">${ResourceBindingsQuery}</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/jasper/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/tomcat7/3.0-SNAPSHOT/car"> <!-- Virtual Host 1 definition --> <gbean name="org.apache.geronimo.configs/tomcat7/3.0/car?ServiceModule=org.apache.geronimo.configs/tomcat7/3.0/car, j2eeType=Host,name=TomcatVirtualHost_1" gbeanInfo="org.apache.geronimo.tomcat.HostGBean"> <attribute name="className">org.apache.catalina.core.StandardHost</attribute> <attribute name="initParams">name=virtualhost1.com appBase= workDir=work</attribute> <reference name="Engine"> <pattern> <name>TomcatEngine</name> </pattern> </reference> </gbean> <!-- Virtual Host 2 and aliases definition --> <gbean name="org.apache.geronimo.configs/tomcat7/3.0/car?ServiceModule=org.apache.geronimo.configs/tomcat7/3.0/car, j2eeType=Host,name=TomcatVirtualHost_2" gbeanInfo="org.apache.geronimo.tomcat.HostGBean"> <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> <reference name="Engine"> <pattern> <name>TomcatEngine</name> </pattern> </reference> </gbean> </module> <module name="org.apache.geronimo.configs/tomcat7-deployer/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/web-extender/3.0-SNAPSHOT/car"/> <module load="false" name="org.apache.geronimo.framework/offline-deployer/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/hot-deployer/3.0-SNAPSHOT/car"> <gbean name="HotDeployer"> <attribute name="path">deploy/</attribute> <attribute name="pollIntervalMillis">2000</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/remote-deploy-tomcat/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/jasper-deployer/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/myfaces/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/myfaces-deployer/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/sharedlib-extender/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/sharedlib/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/aries/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/aries-deployer/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/persistence-jpa20-deployer/3.0-SNAPSHOT/car"> <gbean name="PersistenceUnitBuilder"> <attribute name="defaultPersistenceProviderClassName">org.apache.openjpa.persistence.PersistenceProviderImpl</attribute> <attribute name="defaultPersistenceUnitProperties">openjpa.Log=commons openjpa.jdbc.SynchronizeMappings=buildSchema(ForeignKeys=true) openjpa.jdbc.UpdateManager=operation-order openjpa.Sequence=table(Table=OPENJPASEQ, Increment=100)</attribute> <attribute name="defaultEnvironment" propertyEditor="org.apache.geronimo.deployment.service.EnvironmentBuilder"> <environment:environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:environment="http://geronimo.apache.org/xml/ns/deployment-1.2"> <dependencies> <dependency> <groupId>org.apache.geronimo.configs</groupId> <artifactId>openjpa2</artifactId> <type>car</type> </dependency> </dependencies> </environment:environment> </attribute> </gbean> </module> <module name="org.apache.geronimo.configs/openjpa2/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/system-database/3.0-SNAPSHOT/car"> <gbean name="DerbyNetwork"> <attribute name="host">${ServerHostname}</attribute> <attribute name="port">${DerbyPort + PortOffset}</attribute> </gbean> </module> <module name="org.apache.geronimo.plugins/pluto-support/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.plugins/console-tomcat/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.plugins/plugin-console-tomcat/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.plugins.monitoring/mconsole-ds/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/openejb/3.0-SNAPSHOT/car"> <gbean name="EJBNetworkService"> <attribute name="port">${OpenEJBPort + PortOffset}</attribute> <attribute name="host">${ServerHostname}</attribute> <attribute name="multicastHost">${MulticastDiscoveryAddress}</attribute> <attribute name="multicastPort">${MulticastDiscoveryPort}</attribute> <attribute name="multipointHost">${MultipointHost}</attribute> <attribute name="multipointPort">${MultipointPort + PortOffset}</attribute> <attribute name="multipointServers">${MultipointServers}</attribute> <attribute name="multipointEnabled">${MultipointEnabled}</attribute> <attribute name="multicastEnabled">${MulticastEnabled}</attribute> <attribute name="clusterName">${ClusterName}</attribute> </gbean> <gbean name="DefaultStatefulContainer"> <attribute name="accessTimeout">30</attribute> <attribute name="timeOut">20</attribute> <attribute name="capacity">1000</attribute> <attribute name="bulkPassivate">100</attribute> </gbean> <gbean name="DefaultSingletonContainer"> <attribute name="accessTimeout">30</attribute> </gbean> <gbean name="DefaultBMPContainer"> <attribute name="poolSize">10</attribute> </gbean> <gbean name="DefaultStatelessContainer"> <attribute name="accessTimeout">30</attribute> <attribute name="closeTimeout">5</attribute> <attribute name="maxSize">10</attribute> <attribute name="minSize">0</attribute> <attribute name="strictPooling">true</attribute> <attribute name="idleTimeout">0</attribute> </gbean> </module> <module name="org.apache.geronimo.plugins.monitoring/mconsole-tomcat/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/activemq-broker-blueprint/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/activemq-ra/3.0-SNAPSHOT/car"> <gbean name="ActiveMQ RA"> <attribute name="ServerUrl">tcp://${ActiveMQHostname}:${ActiveMQPort + PortOffset}</attribute> </gbean> </module> <module name="org.apache.geronimo.plugins/activemq-console-tomcat/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.plugins/debugviews-console-tomcat/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.plugins/sysdb-console-tomcat/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.plugins/openejb-console-tomcat/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/openejb-deployer/3.0-SNAPSHOT/car"> <gbean name="EjbRefBuilder"> <attribute name="eeNamespaces">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute> </gbean> <gbean name="ClientEjbRefBuilder"> <attribute name="eeNamespaces">http://java.sun.com/xml/ns/j2ee,http://java.sun.com/xml/ns/javaee</attribute> <attribute name="host">${ServerHostname}</attribute> <attribute name="port">${OpenEJBPort + PortOffset}</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/openejb-corba-deployer/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/j2ee-corba-yoko/3.0-SNAPSHOT/car"> <gbean name="NameServer"> <attribute name="port">${COSNamingPort + PortOffset}</attribute> <attribute name="host">${ServerHostname}</attribute> </gbean> <gbean name="Server"> <attribute name="port">${ORBSSLPort + PortOffset}</attribute> <attribute name="host">${ServerHostname}</attribute> </gbean> <gbean name="UnprotectedServer"> <attribute name="port">${ORBPort + PortOffset}</attribute> <attribute name="host">${ServerHostname}</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/openwebbeans/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/openwebbeans-deployer/3.0-SNAPSHOT/car"/> <module load="false" name="org.apache.geronimo.framework/jmx-security/3.0-SNAPSHOT/car"> <gbean name="JMXSecureConnector"> <attribute name="protocol">rmi</attribute> <attribute name="host">${ServerHostname}</attribute> <attribute name="port">${JMXSecurePort + PortOffset}</attribute> <attribute name="urlPath">/jndi/rmi://${ServerHostname}:${NamingPort + PortOffset}/JMXSecureConnector</attribute> <attribute name="algorithm">Default</attribute> <attribute name="secureProtocol">TLS</attribute> <attribute name="keyStore">geronimo-default</attribute> <attribute name="keyAlias">geronimo</attribute> <attribute name="trustStore">geronimo-default</attribute> <attribute name="clientAuth">false</attribute> </gbean> </module> <module name="org.apache.geronimo.plugins.monitoring/agent-ds/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/mejb/3.0-SNAPSHOT/car"/> <module load="false" name="org.apache.geronimo.plugins.monitoring/agent-car-ejb/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.plugins.monitoring/agent-car-jmx/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/welcome-tomcat/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/javamail/3.0-SNAPSHOT/car"> <gbean name="SMTPTransport"> <attribute name="host">${SMTPHost}</attribute> <attribute name="port">${SMTPPort}</attribute> </gbean> </module> <module name="org.apache.geronimo.plugins/plancreator-console-tomcat/3.0-SNAPSHOT/car"/> <module load="false" name="org.apache.geronimo.configs/client/3.0-SNAPSHOT/car"/> <module load="false" name="org.apache.geronimo.configs/client-security/3.0-SNAPSHOT/car"/> <module load="false" name="org.apache.geronimo.configs/client-corba-yoko/3.0-SNAPSHOT/car"/> <module load="false" name="org.apache.geronimo.configs/client-transaction-1_6/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/client-deployer/3.0-SNAPSHOT/car"> <gbean name="AppClientBuilder"> <attribute name="host">${ServerHostname}</attribute> <attribute name="port">${OpenEJBPort + PortOffset}</attribute> </gbean> </module> <module load="false" name="org.apache.geronimo.configs/openejb-client/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/webservices-common/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/axis/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/axis-deployer/3.0-SNAPSHOT/car"> <gbean name="AxisModuleBuilderExtension"> <attribute name="listener">?name=${webcontainer}</attribute> <attribute name="defaultEnvironment" propertyEditor="org.apache.geronimo.deployment.service.EnvironmentBuilder"> <environment:environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2" xmlns:environment="http://geronimo.apache.org/xml/ns/deployment-1.2"> <dependencies> <dependency> <groupId>org.apache.geronimo.configs</groupId> <artifactId>${webcontainerName}</artifactId> <type>car</type> </dependency> </dependencies> </environment:environment> </attribute> </gbean> </module> <module name="org.apache.geronimo.configs/jaxws-deployer/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/axis2/3.0-SNAPSHOT/car"/> <module condition="props['org.apache.geronimo.jaxws.provider'] == 'axis2' or (props['org.apache.geronimo.jaxws.provider'] == null and webcontainerName == 'tomcat7')" name="org.apache.geronimo.configs/axis2-deployer/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/jaxws-ejb-deployer/3.0-SNAPSHOT/car"/> <module load="false" name="org.apache.geronimo.configs/axis2-ejb/3.0-SNAPSHOT/car"/> <module condition="props['org.apache.geronimo.jaxws.provider'] == 'axis2' or (props['org.apache.geronimo.jaxws.provider'] == null and webcontainerName == 'tomcat7')" name="org.apache.geronimo.configs/axis2-ejb-deployer/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/jaxws-sun-tools/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/jaxws-tools/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.plugins/uddi-db/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/uddi-tomcat/3.0-SNAPSHOT/car"> <gbean name="DerbyProperties"> <attribute name="systemProperties">uddi.openjpa.ConnectionURL=jdbc:derby://localhost:${DerbyPort + PortOffset}/UddiDatabase;create=false;</attribute> </gbean> </module> <module name="org.apache.geronimo.configs/wink/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/wink-deployer/3.0-SNAPSHOT/car"/> <module name="org.apache.geronimo.configs/connector-deployer-1_6/3.0-SNAPSHOT/car"/> </attributes>

Note: Some tags in this config.xml excerpt shown here are presented in multiple lines for displaying purposes only.

Deploying a GBean configuration

First create the GBean. Note the formatting of the <attribute name="initParams"> element which must be left as seen.

gbean-Virtualhost1_com.xml <module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2"> <environment> <moduleId> <groupId>org.example.configs.virtualhosts</groupId> <artifactId>virtualhost1</artifactId> <version>1.0</version> <type>car</type> </moduleId> <dependencies> <dependency> <groupId>org.apache.geronimo.configs</groupId> <artifactId>tomcat7</artifactId> <type>car</type> </dependency> </dependencies> <hidden-classes/> <non-overridable-classes/> </environment> <gbean name="TomcatVirtualHost_1" class="org.apache.geronimo.tomcat.HostGBean"> <attribute name="className">org.apache.catalina.core.StandardHost</attribute> <attribute name="initParams">name=virtualhost1.com appBase= workDir=work</attribute> <reference name="Engine"> <name>TomcatEngine</name> </reference> </gbean> </module>

Deploy the GBean to your Geronimo server.

  • For a single server with no instances:
    • deploy --user system --password manager deploy gbean-Virtualhost1_com.xml
  • For a server with multiple instances:
    • deploy --user system --password manager --port <RMI_port> deploy --targets <instance_repo_target> gbean-Virtualhost1_com.xml
Example deploy [root@server geronimo3]# env GERONIMO_SERVER=gserv1 bin/deploy --user system --password manager --port 1199 deploy --targets Localgserv1 gbean-virtualhost1_com.xml Using GERONIMO_HOME: /opt/geronimo3 Using GERONIMO_SERVER: /opt/geronimo3/gserv1 Using GERONIMO_TMPDIR: /opt/geronimo3/gserv1/var/temp Using JRE_HOME: /usr/jdk1.6.0/jre Deployed org.example.configs.virtualhosts/virtualhost1/1.0/car

The deployed GBean configuration is an installed module. All modules can be listed, which will show the Virtual Host GBean module just deployed.

  • For either a single server with no instances, or server with multiple instances:
    • deploy --user system --password manager --port <RMI_port> list-modules
Example list-modules [root@server geronimo3]# env GERONIMO_SERVER=gserv1 bin/deploy --user system --password manager --port 1199 list-modules Using GERONIMO_HOME: /opt/geronimo3 Using GERONIMO_SERVER: /opt/geronimo3/gserv1 Using GERONIMO_TMPDIR: /opt/geronimo3/gserv1/var/temp Using JRE_HOME: /usr/jdk1.6.0/jre Found 83 modules deployed to 2 targets Target org.apache.geronimo.framework/j2ee-system/3.0-SNAPSHOT/car?ServiceModule=org.apache.geronimo.framework/j2ee-system/3.0-SNAPSHOT/car,j2eeType=ConfigurationStore,name=Local + org.apache.geronimo.configs/activemq-broker-blueprint/3.0-SNAPSHOT/car ... + org.example.configs.gserv1/gserv1repo/2.2/car ... org.apache.geronimo.plugins.monitoring/agent-car-ejb/3.0-SNAPSHOT/car Target org.example.configs.gserv1/gserv1repo/2.2/car?ServiceModule=org.example.configs.gserv1/gserv1repo/2.2/car,j2eeType=ConfigurationStore,name=Localgserv1 + org.example.configs.virtualhosts/virtualhost1/1.0/car

To remove the configuration, undeploy the GBean

  • For either a single server with no instances, or server with multiple instances:
    • deploy --user system --password manager undeploy org.example.configs.virtualhosts/virtualhost1/1.0/car
Example undeploy [root@server geronimo3]# env GERONIMO_SERVER=gserv1 bin/deploy --user system --password manager --port 1199 undeploy org.example.configs.virtualhosts/virtualhost1/1.0/car Using GERONIMO_HOME: /opt/geronimo3 Using GERONIMO_SERVER: /opt/geronimo3/gserv1 Using GERONIMO_TMPDIR: /opt/geronimo3/gserv1/var/temp Using JRE_HOME: /usr/jdk1.6.0/jre Module org.example.configs.virtualhosts/virtualhost1/1.0/car unloaded. Module org.example.configs.virtualhosts/virtualhost1/1.0/car uninstalled. Undeployed org.example.configs.virtualhosts/virtualhost1/1.0/car

Declare the virtual host in the deployment plan

For this topic, the HelloWorld sample application covered in the Quick start - Apache Geronimo for the impatient section is used as an example. Because this is a Web application, the deployment plan that you need to modify is a geronimo-web.xml file. If you use a different type of application, you might need to modify a different deployment plan, for example geronimo-application.xml.

In the previous section, you defined two Virtual Hosts. Now, you can configure two applications so that they can be deployed to those Virtual Hosts exclusively.

The following section uses the same application for the two Virtual Hosts, but will differentiate one deployment from the other by giving it a different artifactId. This way you can identify each deployment without modifying the code.

If you followed the steps covered in the Quick start - Apache Geronimo for the impatient section, your HelloWorld application should have the following structure:

solid <APP_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 that you want this application to listen on, in this case virtualhost1.com.

xmlgeronimo-web.xml for HelloWorld_1solid <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1" xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"> <sys:environment> <sys:moduleId> <sys:groupId>sample.applications</sys:groupId> <sys:artifactId>HelloWorldApp_1</sys:artifactId> <sys:version>2.2</sys:version> <sys:type>war</sys:type> </sys:moduleId> <sys:dependencies/> <sys:hidden-classes/> <sys:non-overridable-classes/> </sys: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_HOME> directory:

jar -cvf HelloWorld_1.war *

When the HelloWorld application is deployed, this application should only be listed in the host with the name virtualhost1.com.

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

xmlgeronimo-web.xml for HelloWorld_2solid <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1" xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2" xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"> <sys:environment> <sys:moduleId> <sys:groupId>sample.applications</sys:groupId> <sys:artifactId>HelloWorldApp_2</sys:artifactId> <sys:version>2.2</sys:version> <sys:type>war</sys:type> </sys:moduleId> <sys:dependencies/> <sys:hidden-classes/> <sys:non-overridable-classes/> </sys:environment> <context-root>hello_2</context-root> <host>virtualhost2.com</host> </web-app>

Save the changes 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.

Deploy the application

At this point, you have configured Geronimo to use two different Virtual Hosts, one of which 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 the following one:

solid D:\geronimo-tomcat7-javaee6-3.0-SNAPSHOT\bin>deploy --user system --password manager deploy \HelloWorld_2.2\HelloWorld_1.war Using GERONIMO_HOME: D:\geronimo-tomcat7-javaee6-3.0-SNAPSHOT Using GERONIMO_SERVER: D:\geronimo-tomcat7-javaee6-3.0-SNAPSHOT Using GERONIMO_TMPDIR: D:\geronimo-tomcat7-javaee6-3.0-SNAPSHOT\var\temp Using JRE_HOME: C:\Java\jdk1.6.0\jre Deployed sample.applications/HelloWorldApp_1/2.2/war @ /hello_1

Repeat the deployment process for the second application.

deploy --user system --password manager deploy <APP_HOME>\HelloWorld_2.war

You should get a successful confirmation message similar to the following one:

solid D:\geronimo-tomcat7-javaee6-3.0-SNAPSHOT\bin>deploy --user system --password manager deploy \HelloWorld_2.2\HelloWorld_2.war Using GERONIMO_HOME: D:\geronimo-tomcat7-javaee6-3.0-SNAPSHOT Using GERONIMO_SERVER: D:\geronimo-tomcat7-javaee6-3.0-SNAPSHOT Using GERONIMO_TMPDIR: D:\geronimo-tomcat7-javaee6-3.0-SNAPSHOT\var\temp Using JRE_HOME: C:\Java\jdk1.6.0\jre Deployed sample.applications/HelloWorldApp_2/2.2/war @ /hello_2

With the applications deployed, you can now test them. To test the first application that has the context-root hello_1, access the host names defined on the Geronimo server machine with the URLs in the following table:

Now repeat the tests for the second application that has the context-root hello_2.

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

  • No labels