• Get application security done the right way! Detect, Protect, Monitor, Accelerate, and more…
  • What is Virtual Host and How to Configure in WebSphere Application Server (WAS)?

    One of the very first terminologies you will hear in WAS Deployment is a virtual host. Many of you asked me about the virtual host and configuration guide so here I have explained the following.

    • What is a virtual host?
    • How to create/configure?
    • How to change virtual hosts in existing deployed applications?
    • Virtual host-related errors
    • Best Practices

    So, what is a Virtual host?

    Virtual host means allowing multiple URL’s (ex – example.com, example.net, example.biz, washost:9443, 10.10.10.1:9060) on a single application through an associated virtual host. This can be either IP-based or name-based. A virtual host configuration is done through WAS administrative console.

    Using a virtual host, you can also define the MIME types. In default WAS installation, you will have two virtual host admin_host & default_host, which you may use or can create the new one for your application. Let’s take a look at below illustration of a virtual host.

    virtual-host-was-flow

    So now you know about the virtual host and next is to create & configure it.

    Virtual host creation is done through WAS administrative console, located under Environment >> Virtual hosts. Let’s create one and name it – sample_hosts

    • Login into WAS Administrative Console
    • Go to Environment >> Virtual hosts
    • Click on New

    You can see two inbuilt virtual hosts in the above list which I mentioned above.

    default-virtual-host-was

    • Enter the name – sample_hosts

    new-virtual-host-was

    • Click on OK

    So now you have a new virtual host and it’s time to configure it.

    There are two types of configuration you can do and both configurations are located inside virtual host under “Additional Properties”.

    Host Aliases: here you can enter DNS/Host/IP Name and Port, which will be allowed, to access the application using this virtual host.

    • Go to Environment >> Virtual hosts
    • Select the virtual host from the list
    • Click on Host Aliases
    • Click on New
    • Enter Host Name & Port
    • Click OK and save/review the configuration and here is what I created

    sample_hosts-virtual-host-was

    MIME Types: here you can add/create/modify MIME types for your application. However, by default WAS would have more than 640+ MIME types created which will cover almost any type of application. This default list is created when you create any virtual host.

    • Go to Environment >> Virtual hosts
    • Select the virtual host from the list
    • Click on MIME Types
    • Click on New to create one. However, as I mentioned above most likely you don’t need to create, as almost all types of applications will be covered with default lists.

    So next is to change virtual host in a deployed application

    There might be a scenario where you got to segregate virtual hosts based on application. Here is how you can change the virtual host for any application.

    • Login into WAS administrative console
    • Go to applications>> Websphere enterprise applications
    • Select your application and click on Virtual hosts located under Web Module Properties
    • Select the desired virtual host and click on OK

    change-virtual-host-was

    • Click on Review/Save the configuration. You must restart the JVM in order to get the virtual host reflected.

    You might be interested to know the virtual host configuration is stored in virtualhosts.xml. Location may differ from environment to environment so the best way to find the exact location of virtualhosts.xml is: –

    On UNIX environment

    find / -name virtualhosts.xml

    Through WAS Console

    When you make any changes in the virtual host it will ask you to review/save. Click on Review and it will show you the path of virtualhosts where it will save the configuration.

    Now the time to go through world-famous WebSphere error related to the virtual host, which is most likely due to either not configured, or misconfiguration.

    Error related to Virtual host

    A WebGroup/Virtual Host to handle /test has not been defined SRVE0255E: A WebGroup/Virtual Host to handle localhost:8080 has not been defined.

    If you are getting the above error when you access the application then you will learn in just a few minutes how to fix it.

    Let’s take a look at the error carefully. There are two things you got to look which I highlighted in red color.

    Firstlocalhost has not been defined

    The application is throwing an error because the localhost doesn’t exist in Host Aliases of a respective virtual host. So quick fix is to add localhost in your virtual host.

    This could be also when you have multiple virtual host and application is mapped to an incorrect virtual host. So you got to review the configuration and ensure the localhost exists in the requested virtual host.

    Second8080 port number

    Most of the time you will configure the virtual host with URL and default Http/https port, which is 80 or 443. However, if you want to access the application directly (bypassing web server) by using JVM and port you need to enter IP/Host and Port details in Host Aliases.

    So to fix this – you got to ensure localhost:8080 is added to a virtual host, which is mapped to the respective applications.

    Last section of this article – Best practices of using Virtual Host in WAS environment.

    Every application is unique and one configuration may not work well in others. However, there are some rules you may follow which has helped me, and hopefully you too.

    • If you are having multiple applications in a single cell, you may consider using a separate virtual host for each or at least for a group of applications.
    • Take a backup of WebSphere configuration before you make any changes so if something goes wrong you may recover to the original state without damage.
    • Restart mapped JVM after making changes to the virtual host so configuration is reflected.
    • Propagate (if managed webserver) & Generate Web Server plugin and restart Web Server to get the configuration reflected.
    • Don’t put * in Host Aliases as this means any URL is allowed which may lead to a security loophole.

    I hope you have a better understanding of Virtual Host in IBM WebSphere Application Server now. that’s all for today and I hope you like it.

    If you are looking to learn WAS administration then you may check out this Udemy course.