Wednesday, October 15, 2014

VIP (Virtual IP) and Virtual Host

Virtual IP
A Virtual IP (VIP) maps one external IP address and one external port to a multiple number of possible IP addresses and ports. It can also translate an external port to a different internal port. VIP addresses map traffic received at one IP address to another address based on the destination port number in the TCP or UDP segment header. If you have only one public IP address available, and you want to host multiple servers, use a VIP. An MIP should be used when you have multiple public IP addresses, and you want to host a single server to a single public IP. A VIP is the equivalent of what many network engineers call port forwarding. For example:

An HTTP packet destined for 210.1.1.3:80 (that is, IP address 210.1.1.3 and port 80) might be mapped to a Web server at 192.168.1.10.
An FTP packet destined for 210.1.1.3:21 might be mapped to an FTP server at 192.168.1.20.
An SMTP packet destined for 210.1.1.3:25 might be mapped to a mail server at 192.168.1.30.

Virtual Host
Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries.
Server configuration

 # Ensure that Apache listens on port 80  

 Listen 80 
 # Listen for virtual host requests on all IP addresses 
 NameVirtualHost *:80 
 <VirtualHost *:80> 
 DocumentRoot /www/example1 
 ServerName www.example.com 
 # Other directives here 
 </VirtualHost> 
 <VirtualHost *:80> 
 DocumentRoot /www/example2 
 ServerName www.example.org 
 # Other directives here 
 </VirtualHost> 

No comments: