Mainly there are 2 types of virtual hosting: name based and ip based virtual hosting.
With the name based virtual hosting you can host several domains/websites on a single machine with a single IP. All domains on that server will be sharing a single IP.
With the IP based virtual hosting, you can assign a separate IP for each domain on a single server, these IP’s can be attached to the server with single NIC cards and as well as multiple NICs.
Name based Virtual Hosting:
First update and then install apache2 package
#apt-get update
#apt-get install apache2
#service start apache2
#cd /var/www/html
Create test1 and test2 folders where we host our websites
#mkdir test1.com
#cd test1.com && vi index.html
Enter the following html code there
<html>
<head>
<title>Welcome to test1.com!</title>
</head>
<body>
<h1>Success! The test1.com virtual host is working!</h1>
</body>
</html>
Now create a directory for second site
#cd ..
#mkdir test2.com
#cd test2.com && vi index.html
Enter the following html code there
<html>
<head>
<title>Welcome to test2.com!</title>
</head>
<body>
<h1>Success! The test2.com virtual host is working!</h1>
</body>
</html>
Now configure our virtual hosting files
#cd /etc/apache2/sites-available/
#vi test1.com.conf
Make the entries as follows
#vi test2.com.conf
Now enable test1.com.conf and test2.com.conf
#a2ensite test1.com.conf
#a2ensite test2.com.conf
Disable 000-default.conf
#a2dissite 000-default.conf
Now go to /etc/hosts file
#vi /etc/hosts
Restart apache2 service
#service apache2 restart
Now go to browser and check www.test1.com and www.test2.com .Thus we can host multiple websites on same machine.
Ipbased Virtual hosting:
In ip based virtual hosting we have to attacg multiple nic card
Now our ubuntu machine will have 2 ip.Here I have Ip1=52.172.205.155 ip2=52.172.205.156
The only difference is that our configuration file should be as follows:
#vi test1.com.conf
#vi test2.com.conf
Now enable test1.com.conf and test2.com.conf
#a2ensite test1.com.conf
#a2ensite test2.com.conf
Disable 000-default.conf
#a2dissite 000-default.conf
#vi /etc/hosts
#service apache2 restart
Now access both ip’s through browser and we can see that’s working fine
With the name based virtual hosting you can host several domains/websites on a single machine with a single IP. All domains on that server will be sharing a single IP.
With the IP based virtual hosting, you can assign a separate IP for each domain on a single server, these IP’s can be attached to the server with single NIC cards and as well as multiple NICs.
Name based Virtual Hosting:
First update and then install apache2 package
#apt-get update
#apt-get install apache2
#service start apache2
#cd /var/www/html
Create test1 and test2 folders where we host our websites
#mkdir test1.com
#cd test1.com && vi index.html
Enter the following html code there
<html>
<head>
<title>Welcome to test1.com!</title>
</head>
<body>
<h1>Success! The test1.com virtual host is working!</h1>
</body>
</html>
Now create a directory for second site
#cd ..
#mkdir test2.com
#cd test2.com && vi index.html
Enter the following html code there
<html>
<head>
<title>Welcome to test2.com!</title>
</head>
<body>
<h1>Success! The test2.com virtual host is working!</h1>
</body>
</html>
Now configure our virtual hosting files
#cd /etc/apache2/sites-available/
#vi test1.com.conf
Make the entries as follows
#vi test2.com.conf
#a2ensite test1.com.conf
#a2ensite test2.com.conf
Disable 000-default.conf
#a2dissite 000-default.conf
Now go to /etc/hosts file
#vi /etc/hosts
Restart apache2 service
#service apache2 restart
Now go to browser and check www.test1.com and www.test2.com .Thus we can host multiple websites on same machine.
Ipbased Virtual hosting:
In ip based virtual hosting we have to attacg multiple nic card
Now our ubuntu machine will have 2 ip.Here I have Ip1=52.172.205.155 ip2=52.172.205.156
The only difference is that our configuration file should be as follows:
#vi test1.com.conf
#vi test2.com.conf
Now enable test1.com.conf and test2.com.conf
#a2ensite test1.com.conf
#a2ensite test2.com.conf
Disable 000-default.conf
#a2dissite 000-default.conf
#vi /etc/hosts
#service apache2 restart
Now access both ip’s through browser and we can see that’s working fine