Virtual Hosts Configuration with Weblogic Server

Virtual Hosts

Virtual hosting, which defines a set of host names to which WebLogic Server instances (servers) or clusters respond. When you use virtual hosting, you use DNS to specify one or more host names that map to the IP address of a server or cluster.

When you deploy the application on virtual host, it means you hide the IP address of the servers which are actually going to serve the requests.

It can either be targeted to one individual server or the whole cluster.

In my example, I have configured a virtual host for the admin server. Below are the steps we need to follow:

1)    The first requirement for creating a virtual host is to create a network channel on the admin server.
–    Go to the admin console, click on servers -> admin server
–    Go to the Protocols -> Channel tab
–    Give the name of the channel as port-80, choose the protocol as http.
–    Give listen address as localhost, give the listen port as 80. Leave the external listen address and port bank.
–    Enable HTTP tunneling as per your preference.
–    Leave the security part as it is to the default unchecked values.
–    You will see the below configuration once the channel is created.

– Restart the server to confirm that the server is using the default channel and port-80 channel.

2) Once the network channel is created, go to Environment -> Virtual hosts
– Click on new, give a name to the host vh.localhost.org.
– Now click on the virtual host vh.localhost.org, give the below values:
Virtual Host Names:  vh.localhost.org
Network Access Point Name: port-80

–    Click on targets tab, check the admin server.
–    Save the changes and restart the server.

3)    Now we need to modify the windows host file in C:\WINDOWS\system32\drivers\etc directory and add the host name vh.localhost.org which we have specified for the virtual host. Add the below in the file:
127.0.0.1    vh.localhost.org

4) Now deploy one test application following the below steps:
– Click on deployments
– Click on install -> Choose the application from the path
– Click next, check Install this deployment as an application -> target it to the virtual host (not the server)

– Click finish

Deployment state should be active.

Now access the application using the url:
http://vh.localhost.org/web-app

You should see the welcome page of the application.

33 comments

  1. Hi Divya,

    Is there a way to deploy applications and target them to virtual hosts using WLST ?

    I have tried to do even the recording option but it was useful.

    Thanks in Advance.

    Regards,
    Kiran

  2. Hi Kiran,

    Yes targeting the application to virtual host using WLST can be done as below:

    – Once you are connected to the server, enter the online command:
    deploy(appName=’web-app’, path=’C:\web-app’, targets=’vh.localhost.org’)

    vh.localhost.ors is the virtual host. It will look like below:

    ==================
    wls:/Channel_vh_domain/serverConfig> deploy(appName=’web-app’, path=’C:\web-app’, targets=’vh.localhost.org’)
    Deploying application from C:\web-app to targets vh.localhost.org (upload=false) …

    .Completed the deployment of Application with status completed
    Current Status of your Deployment:
    Deployment command type: deploy
    Deployment State : completed
    Deployment Message : no message

    Let me know if this works for you.

    Regards,
    Divya

  3. Hey Divya
    in url is it manadatory to specify the port number in virtualhost ?
    i have tried one example , if i am not giving the port application is not working .in above exaple you haven’t given the port. is any specific rule for giving thevirtualhost name ( means how many character and dots ican give ex:- vh.madhu.test.org can i use this ?

  4. Hi Madhukar,

    In the above example, the port number i have given is 80. And this port number does not need to be entered in the url. If you give any other port number, for e.g. if i have port number as 7001, the url has to be something like http://vh.localhost.org:7001/web-app.

    For giving the virtual host name, there is no rule i know of. It can be a single word or there can be dots too. Let me know if these things work for you.

    Thanks!
    Divya

  5. Hi,

    Thanks for your document. I tried but not showing target server for vh.localhost.org. I am using weblogic 9. Please tell me how i can connect virtual host

  6. Thank you divya. If we are using other than port 80 we have to mention in th URL .. please correct me if i am wrong .

    In windows vista aprache proxy plugin is not working .
    Please suggest me is vista is not compatablie for proxying the requests WEBLOGIC AND APACHE.

    i am using the weblogic 9.2 and apache 2.2.x . Same was working fine in Windows XP

  7. Thanks so much for this post – I found such gobbledygook on the Oracle support discussions that I was beginning to despair. This is a lifesaver!

  8. I have question. If it will work without defining anything in Apache httpd.conf file.I think the virtual host entries must be reflect in this file also.
    please make me correct if I am wrong

  9. i have tried with virtualhost but i am getting some server side exception :
    503 Service Unavailable
    Failed to resolve the name of server vh.localhost.org to connect

    i have included the virtualhost in hosts file also
    logs are showing
    —————————————————————————

    [HttpServer (VirtualHost) name: vh.localhost.org hosts: [vh.localhost.org] channel: port-80] Initialized>

    can any one please help me on this

    Thanks in Advance

    cheers,
    Ananth

    1. Hi Ananth,

      Can you give me a breif outline of the steps you have followed? I doubt this can be something to do with the network channel.

      Best Regards,
      Divya

  10. Thanks for the explanation. couple of questions.

    1) in step 4 , isnt the application required to be targeted to the admin server ?

    2) can you give some examples where the weblogic virtual hosting is used. I am little confused as to why to use weblogic virtual hosting when the same thing can be done using Apache or Iplanet in a much more efficient way.

    1. Hi Ram,

      It would be targetted to the virtual host because that is the purpose of creating it. This virtual host is made for the admin server (check the step 1). If it is targeted to the admin server, virtual host cannot be used.

      About the second question, it depends on you what you prefer. Even in weblogic you can create many virtual hosts and target it to different set of servers or a cluster. It gives you a lot of flexibility.

      Best Regards,
      Divya

  11. Divya,

    I have created http-channel with port “80”
    i have used same channel in virtual-host configuration after that i
    have modified hosts file
    i have deployed sample WAR file with weblogic-deployeer utility
    i have tried with http://vh.localhost.org/sample
    i got error like

    Failed to resolve the name of server vh.localhost.org to connect

    1. Hi Ananth,

      Did you target that application to the virtual host? Also please tell me what exact error you are seeing after the line failed to connect? I hope you restarted the server after creating the virtual host.

      Best Regards,
      Divya

Leave a Reply