Wednesday, 15 May 2013

Configuring Virtual Servers in Glassfish

Using Virtual Server we can host multiple websites in a single glassfish domain. If you are familiar with virtual hosting in web servers, it is the same feature as virtual hosting.

Here I will configure two applications app1 and app2 in one Glassfish server. The requirement is that and should open the app1 application. Also and  should open app2 application.

Both the applications are deployed in domain1 of my glassfish server.

First I will change the default HTTP port for Glassfish domain1 so that it listen to port 80. Go to server-config –> Network Config –> Network Listeners –> http-listener-1

Change to Port to 80 and save it.




Now I will create Virtual Server for the first application (app1).

Login to Glassfish Admin console.

Go to Configurations –> server-config –> Virtual Servers



By default we can see the two Virtual Servers, _asadmin and server:



Click on the New button to create the new Virtual Server for app1.

Enter ID for this configuration, Glassfish will refer the new Virtual Server using this name.

Hosts: This will be the comma separated list of hosts or IP address using which we gonna access this application. For the app1 it will be and 

Select State as On – Virtual server active

As I don’t need single sign on, so I kept SSO disabled.

Select the Network Listeners which will be attached to this Virtual Server.

Select the Default Web Module as app1 (the default application that will be accessed using this virtual server).

Enter the error and access log file locations if you want separate access and error logs for this Virtual server.

Now in Docroot I have entered the location where my application app1 resides i.e.  ${com.sun.aas.instanceRoot}/applications/app1/

Click Ok to create the Virtual Server.




Same way I will create the second virtual server for my second application app2.



That’s it, my virtual servers are ready and now I can directly open, and, without specifying context path Smile