Virtual Hosting in Apache

Virtual Hosting is a term used to refer the practice of running multiple websites on a single machine.Virtual hosts can be IP-based, meaning that you have a different IP address for every web site, or name-based, meaning that you have multiple names running on each IP address. The fact that they are running on the same physical server is not apparent to the end user.

The following commands are tested on RedHat and CentOS.

Add the following lines in your configuration file

# vi /etc/httpd/conf/httpd.conf  
<VirtualHost *:80>
ServerAdmin root@server.example.com   
ServerAlias server2.example.com  
DocumentRoot /home  
ServerName storage.estuate  
ErrorLog logs/deepak.example.com.log   
CustomLog logs/deepak.example.com.access_log  
</VirtualHost>  

Here "" signifies your apache server will listen to any IP you have used for web server configuration on your machine. You should make an habbit of using proper IP or name instead of "".

ServerAdmin ==> sets the contact address that the server includes in any error messages it returns to the client.If the httpd doesn't recognize the supplied argument as an URL, it assumes, that it's an email-address and prepends it with mailto: in hyperlink targets. However, it's recommended to actually use an email address.

ServerAlias ==> This directive sets the alternate names for a host.

ServerName ==> This directive sets the request scheme, hostname and port that the server uses to identify itself. This is used when creating redirection URLs.

DocumentRoot ==> This directive specifies the root directory of the files you want to be visible on your web server

Adding some more features to your virtual hosts

# vi /etc/httpd/conf/httpd.conf  
<VirtualHost *:80>  
ServerAdmin root@server.example.com   
ServerAlias server2.example.com  
DocumentRoot /home  
ServerName storage.estuate  
<Directory /home/deepak/mypage.html>  
AllowOverride None  
Order Deny,Allow  
Deny from All   
</Directory>   
</VirtualHost>   

AllowOverride None will disable the access to .htaccess file

By default users are allowed to access all the directories inside the document root on the web server. To override this rule we use the following directive

<Directory /home/deepak/mypage.html>  
Order Deny,Allow   
Allow from all   
</Directory>   

You can check one example of virtual hosting with all the above directives used in the following post
yum configuration using apache server

Follow the below links for more tutorials

What is a Kernel in Linux?
How does a DNS query works when you type a URL on your browser?
How to create password less ssh connection for multiple non-root users
How to create user without useradd command in Linux
How to unlink/delete a symbolic in Linux
How to give normal user root privileges using sudo in Linux/Unix
How to do Ethernet/NIC bonding/teaming in Red Hat Linux
How to install/uninstall/upgrade rpm package with/without dependencies

Multiple connections to a server or shared resource by same user
How to extract files to different directory using tar in Unix/Linux
How to preserve Symbolic links with tar command in Unix/Linux