Hi,

Jay SenSharma

Jay SenSharma

To get a Brief introduction of Why We Need Virtual Hosts, Please refer to:  configuring-virtual-hosts/

Here is a Very basic Demo/Sample of Using / Configuring the Virtual Hosts. In the following Example We will Create a Virtual Host targeted to the AdminServer. Then we will deploy an application targeted to the Virtual host. Then we will see that we WON’T be able to access the application with http://localhost:7001/TestApp/index.jsp or http://xyz:7001/TestApp/index.jsp rather we can access that application only throught the Virtual Host name: http://abc:7001/TestApp/index.jsp

Step1). Open the “hosts” file of your Operating System. In Windows Open the Hosts file from the following Location: C:WINDOWSsystem32driversetc
and Edit it like following:

Changing Hosts File

Changing Hosts File

Step2). Try to access the Admin Console Using the following URLs now…just to see that the “C:WINDOWSsystem32driversetchosts” file changes have taken effect or not? (No Need to restart your Operating System or WLS Server)

http://localhost:7001/console
http://abc:7001/console
http://xyz:7001/console

Accessing Console Using Different Host Names

Accessing Console Using Different Host Names

Step3). Login to AdminConsole and then Configure the Virtual Host as following:
Home –>Summary of Virtual Hosts –>New

Creating New VirtualHost

Creating New VirtualHost

Assigning Display Name to Virtual Host

Assigning Display Name to Virtual Host

Step4). Now Click on the newly created “MyVirtualHost” to set the Target of it…

Configuring Virtual Host Parameters

Configuring Virtual Host Parameters

Targeting Virtual Host to AdminServer

Targeting Virtual Host to AdminServer

Step5). Once you see the following configuration…for your Virtual Host…Now Restart the Server. Restarting the Server is Most IMPORTANT sothat the Changes will get reflected.

Step6). Now develope a Simple Application having a Simple JSP or HTML Page inside it. Create a Directory somewhere in your File System:
Example: C:VirtualHostDemo

Step7). Provide a Simple “index.jsp” page inside “C:VirtualHostDemo” as following:

<html>
<head><title>Virtual Host Example</title></head>
<body>
<center><h2>Are u Able to Access the Application Using Virtual Host Name?</h2></center>
</body>
</html>

Step8). Provide a Simple “web.xml” file inside “C:VirtualHostDemoWEB-INF” as following:

<?xml version=’1.0' encoding=’UTF-8'?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

Step9). Develope a Simple “build.xml” file to deploy the Application on the Server. Create a “build.xml” file in “C:” root drive:

<project name="webservices-hello_world" default="deploy">
<!-- set global properties for this build -->
<property name="wls.username" value="weblogic" />
<property name="wls.password" value="weblogic"/>
<property name="wls.hostname" value="localhost" />
<property name="wls.port" value="7001? />
<property name="wls.server.name" value="MyVirtualHost" />

<target name="deploy">
<wldeploy action="deploy" name="VirtualHostDemo" source="VirtualHostDemo"
user="${wls.username}" password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}" targets="${wls.server.name}" />
</target>

<target name="undeploy">
<wldeploy action="undeploy" name="VirtualHostDemo" failonerror="false"
user="${wls.username}" password="${wls.password}" verbose="true"
adminurl="t3://${wls.hostname}:${wls.port}" targets="${wls.server.name}" />
</target>
</project>

Step10). Now Deploy the Application on the Server Using the above ANT Script targeted to the Virtual Host (Not to a Perticular Serever) as following:

Deploying Sample Application Targeted to Virtual Host

Deploying Sample Application Targeted to Virtual Host

Access the Application Using Duifferent URLs

Access the Application Using Duifferent URLs

.
.
Thanks
Jay SenSharma

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.