We can host multiple websites from a single server to utilize the server resources appropriately.
If we are using apache as our web-server, we can do this by two ways:
1.) IP-based virtual hosting:
In IP-based virtual hosting, we are running more than one web site on the same server machine, but each web site has its own IP address.
But, we require multiple IPs in that single server and to assign multiple IPs, we require multiple interface cards.
In Linux based OS we can use below command to add a new virtual interface upon physical interface card and assign IPs to the same:
Here we have 1 physical NIC card eth0 from which we have created 3 virtual NIC card eth0:0, eth0:1, eth0:2 with IP address 192.168.10.1, 192.168.10.2, 192.168.10.3 respectively
.
The server has three IP addresses (192.168.10.1, 192.168.10.2, and 192.168.10.3) which resolve to the names www.example.com, www.example.org and www.example.gov respectively.
Below is the sample apache configuration file to use IP based virtual hosting, we can have separate configuration file for each website as well.
In the above configuration file, we have placed our website code for www.example.com, www.example.org, www.example.gov under /www/example, /www/example2 and /www/example3 respectively.
We can add number of virtual interfaces as per our requirement and assign relevent IP and host multiple websites.
2.) Name Based Virtual Hosting:
Name based virtual hosting is a method of running multiple web sites using only one IP Address. It is possible because the HTTP Protocol includes the target address in its headers.
In this configuration, when Apache webserver receives a request, it looks for the hostname in the HTTP header, and depending on the hostname, it servers different websites. In this case we need only one IP-address on that physical server; but, we have to update the DNS with multiple website names pointing to the same IP-address.
For update the website name in DNS we have to update forward lookup zone file and backward lookup zone file.
For forward lookup zone entry:
For reverse lookup zone entry:
Now server configurations in apache configuration file for several name based hosting on single IP.
Where,
• NameVirtualHost IP – Indicates that all the name-based virtual hosts will be match that IP
• <VirtualHost IP> </VirtualHost> – Enclose all the apache configuration parameters for each and every virtual host between these VirtualHost tags. Any apache directives can be used within the virtualhost container.
• ServerName listens for requests asking for a certain domain
• DocumentRoot is the path to the content for that site
• In the following example, we are setting up virtual host for www.example.com and www.example.org on single IP. So, there will be two <VirtualHost IP> </VirtualHost>, one for each website.
Bazinga... Done. Cheers!!
Thanks Vikas for your input.
Keep visiting and please comment/suggest or ask queries if any.
If we are using apache as our web-server, we can do this by two ways:
![]() |
| Shared Hosting |
1.) IP-based virtual hosting:
In IP-based virtual hosting, we are running more than one web site on the same server machine, but each web site has its own IP address.
But, we require multiple IPs in that single server and to assign multiple IPs, we require multiple interface cards.
In Linux based OS we can use below command to add a new virtual interface upon physical interface card and assign IPs to the same:
![]() |
| Create virtual interface card |
Here we have 1 physical NIC card eth0 from which we have created 3 virtual NIC card eth0:0, eth0:1, eth0:2 with IP address 192.168.10.1, 192.168.10.2, 192.168.10.3 respectively
.
The server has three IP addresses (192.168.10.1, 192.168.10.2, and 192.168.10.3) which resolve to the names www.example.com, www.example.org and www.example.gov respectively.
Below is the sample apache configuration file to use IP based virtual hosting, we can have separate configuration file for each website as well.
![]() |
| Sample IP based virtul hosting |
In the above configuration file, we have placed our website code for www.example.com, www.example.org, www.example.gov under /www/example, /www/example2 and /www/example3 respectively.
We can add number of virtual interfaces as per our requirement and assign relevent IP and host multiple websites.
2.) Name Based Virtual Hosting:
Name based virtual hosting is a method of running multiple web sites using only one IP Address. It is possible because the HTTP Protocol includes the target address in its headers.
In this configuration, when Apache webserver receives a request, it looks for the hostname in the HTTP header, and depending on the hostname, it servers different websites. In this case we need only one IP-address on that physical server; but, we have to update the DNS with multiple website names pointing to the same IP-address.
For update the website name in DNS we have to update forward lookup zone file and backward lookup zone file.
For forward lookup zone entry:
| Forward look-up zone |
For reverse lookup zone entry:
| Reverse lookup zone |
Now server configurations in apache configuration file for several name based hosting on single IP.
![]() |
| Name based virtual hosting |
Where,
• NameVirtualHost IP – Indicates that all the name-based virtual hosts will be match that IP
• <VirtualHost IP> </VirtualHost> – Enclose all the apache configuration parameters for each and every virtual host between these VirtualHost tags. Any apache directives can be used within the virtualhost container.
• ServerName listens for requests asking for a certain domain
• DocumentRoot is the path to the content for that site
• In the following example, we are setting up virtual host for www.example.com and www.example.org on single IP. So, there will be two <VirtualHost IP> </VirtualHost>, one for each website.
Bazinga... Done. Cheers!!
Thanks Vikas for your input.
Keep visiting and please comment/suggest or ask queries if any.










0 comments:
Post a Comment