Sunday, October 2, 2011

Creating Virtual Hosts in Apache

I am sure most of what I am writing is available on the Apache Documentation but posting this so that it will be helpful for Users to configure Simple Virtual Hosts easily and faster. 

To start with "What is a VIRTUAL HOST"??
It is a method of Hosting multiple domain names on a server using a Single IP address. This allows sharing of resources of one server such as memory, processor cycles etc which lead to efficient utilization of the resources increasing the efficiency.

Now all of us know Apache is the HTTP Web Server which stores and maintains large number of Websites, It is designed to achieve a very high performance. To configure Virtual Host in Apache is very simple. It involves performing a few steps:


1.Firstly, Install the new Apache Web Server from the http://httpd.apache.org/ site. The downloads for all the OS are available.

2.After installation the Apache will be present in the following directory by default in case of Windows:  "C:\Program Files\Apache Software Foundation\Apache2.X" or "C:\Program Files (x86)\Apache Software Foundation\Apache2.X" in case if 64-bit machines.The httpd.conf file is present under the "conf" folder.
To create Virtual hosts define the following entries in the httpd.conf file which is present under "C:\Program Files\Apache Software Foundation\Apache2.X\conf" directory.

3.Open the file.In the beginning of the file there will be an entry to Listen on a particular port. By default the port is 80.
To create Virtual Hosts which run on port 81 and 82, include the lines after the Listen 80 line ie:            
    Listen 80 
    Listen 81                
    Listen 82
   .  
 
4.Now go to the bottom of the file and search for the entry:
         # Virtual hosts
         #Include conf/extra/httpd-vhosts.conf
       
5.Add the following under the entry:
          NameVirtualHost *:81
          NameVirtualHost *:82


         <VirtualHost *:81>
         DocumentRoot "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs1"
         ServerName www.example1.com


         # Other directives here


         </VirtualHost>


         <VirtualHost *:82>
        DocumentRoot "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs2"
        ServerName www.example2.org


        # Other directives here


       </VirtualHost>
    Note: The directory htdocs1 and htdocs2 should be created.
 6.Edit the hosts file located under the System32/drivers/etc/ directory. Add the two entries:
           <ip_address of the machine> www.example1.com         
           <ip_address of the machine> www.example2.com

 7.Save the file and close it. restart the Apache Web server either from Services or console.
 Access the link : http://www.example1.com:81/. It should redirect the control to the htdocs1 directory.Place few files in this directory. It must be served.
 Similary, accessing http://www.example2.com:82/ should be redirected to htdocs2 directory. To access the htdocs folder http://localhost:80/ will do.

Thus, We have setup a dedicated Virtual Host setup in Apache. 

Thursday, September 22, 2011

Caching in ColdFusion-Brief Overview

Well... Am sure most of us will be aware of what a Cache does.It is nothing but a component that temporarily stores data so that it can be referenced when future requests to the same data are made at a faster rate. Thus, it saves the time required to access the data from the disk or any other location improving the efficiency. The various advantages of caching are:

1. Enables accessing of the data at a faster rate.
2. Improves performance
3. In case of Web based applications, caching reduces the load on the Web server or Application server.
4. Increases reliability.(If the main server goes down, then data can be retrieved from the cache or vice-versa)

Adobe ColdFusion is an application server which enables developers to build, deploy and maintain large Internet based applications which store large amount of data. Since large amount of data transactions will be carried out, caching is a very important requirement. In case of ColdFusion a Web cache sits in between one ore more Web servers and one or more clients. This Web cache stores the data and can be accessed when the request for that data is made. This avoids the call to the Web Server to fetch the data thus reducing Latency. As the data is reused it reduces the representations used by the client which reduces the amount of bandwidth used by the client.  This lowers Network Traffic. Since the load is borne both by the Web cache and the Web Server's Database or the App server's database, the memory is efficiently managed which reduces the Garbage collection and the load is efficiently distributed. This makes the data more reliable since data is present in both the places and if server goes down data can still be retrieved from the cache.

proxy_caching.jpg

We all know that ColdFusion makes use of ehcahe as the cache provider for caching data. By default, the ehcache is stored within the CF address space. The different Caching architectures which are used are:

  1. In-Process Architecture : Operates in the same JVM as the application server. It has limited scalability for 32-bit systems as memory constraint must be considered. The data access is faster in this architecture as data/object serialization is not required.                                                                                             
  2. Out-of-Process Architecture : Operates in its own process outside the application server's JVM. It is highly scalable on both 32-bit and 64-bit platforms. It is generally slower than In-Process architecture as data/objects must be serialized/deserialized. 

The different types of Cache regions present in ColdFusion by default are:
  1.     Object Cache: It is the most flexible way to cache data. it can cache anything put in a ColdFusion variable.It has granular control over cache functions.It has access to the various cache item meta data such as cache_hitcount,cache_misscount,hitcount,idletime etc. It uses ehcache as cache provider.
  2.     Template Cache :  It can be used to cache a whole page by placing a <cfcache> tag at the top for the page. It can cache page fragments by placing the <cfcache> tag in between pages which have to be cached. It is useful when part of the page should be dynamic. It uses ehcache as cache provider
ColdFusion had caching in the <cfquery> tags in the previous versions. Query cache does not use ehcache as cache provider. In version 9, there were many enhancements added. Some of them were:
  1. Disk based and Memory based Caching
  2. Cfcache to use ehcache as default cache provider. This ehcache.xml is present under     <coldfusion_home>/lib directory
  3. Caching Page Fragements
  4. Introduced new functions such as
      *cacheGet
      *cachePut
      *cacheGetAllIds
      *cacheGetMetaData
      *cacheGetProperties
      *cacheSetProperties
    Refer to http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec1b05d- 7fe1.html for detailed explanation.
 5. New attributes are added to the <cfcache> tag . Refer
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d5a.html for detailed explanation.