Thursday, July 4, 2013

Virtual Host Configuration in Websphere Using Jython and Webserver(Apache or IHS)

What is Virtual Host?

      A virtual host is a configuration  that enables a single host machine to resemble multiple host machines.
Example:Consider  a web hosting company with one webserver.But they can host one or more websites using the same webserver with virtual host configuration.

Virtual Host Configuration in Webserver:

   In httpd.conf file the below lines will be there for virtual host settings:

<VirtualHost *:80>
  ServerName www.example.com
  DocumentRoot /var/www/example
</VirtualHost>
 
<VirtualHost *:80>
  ServerName www.test.com
  DocumentRoot /var/www/test
</VirtualHost> 

In this example Both the  websites www,example.com and www.test.com 
are using the port 80.The files needed for those websites are present in
the respective document root location.
 
Once configuration changes are done in httpd.conf for webserver we can check the 
settings are proper by the command httpd -S.This will result in Syntax OK if 
everything is fine,else corresponding error will be displayed.
 
Use curl command to test the website URL :
curl -I www.example.com 

nslookup ipaddress of the server to check DNS mapping is fine.

Virtual Host Configuration in Websphere:

  1.In Administration Console,Under Environment ->VirtualHosts ->New .
  2.Enter a name for your virtual Host and Save.
  3.Click on newly created Virtual Host and Under Additional Properties, click Host Aliases.
  4.Click New to create host aliases Enter the hostname and port.Use * for all hosts.
  5.Save the configuration.

Jython Script to configure Virtual Host: 

 import sys

new_host=sys.argv[1]
host_name=sys.argv[2]
port=sys.argv[3]
AdminConfig.create('VirtualHost', AdminConfig.getid('/Cell:AdminControl.getCell()/'), '[[name, "+new_host+"]]')
AdminConfig.create('HostAlias', AdminConfig.getid('/Cell:AdminControl.getCell()/VirtualHost:"+new_host+"/'), '[[port ,"+port+"] [hostname ,"+host_name+"]]')

Save this into virtual.py and execute  with cmd ./wsadmin.sh -lang jython -f virtual.py test localhost 9080
test - Virtual Host Name
localhost-HostName
9080-Port
  
  


No comments:

Post a Comment

Your suggestions please