Virtual hosting is a method for hosting multiple websites on a single server. There are two types of virtual hosting: Name based virtual hosting and IP-based virtual hosting. IP-based virtual hosting is a technique to apply different directives based on the IP address and port a request is received on. You can assign a separate IP for each domain on a single server using IP-based virtual hosting. Mostly this is used to host different websites on different ports or IPs.
Here we are going to host “www.ipvhost1.com” on IP “192.168.1.227”, “www.ipvhost2.com” on IP “192.168.1.228” and “www.portvhost.com” on IP “192.168.1.228” with Port 8080.
OS: Ubuntu server 14.04 with Apache installed
IP address1: 192.168.1.227
IP address2: 192.168.1.228
Create Multiple IP Addresses On Single Network Interface
To setup IP-based virtual hosting, you must have more than one IP address assigned to your Linux machine. Setting up multiple IP addresses on a single network interface is called IP aliasing. IP aliasing is very useful if you have only one network interface card.
To do this, you need to edit the “/etc/network/interfaces” file.
Now, it’s time to test the IP Virtualhost. On a computer, open your web browser and navigate to URLs “http://192.168.1.227:80” and “http://192.168.1.228:80”. You should see sample demo pages for IP-based virtual hosting that look like this:
Similarly, to test Port Virtualhost, open your web browser and navigate to URL “http://192.168.1.228:8080”. You should see a sample demo page for Port-based virtual hosting that looks like this:
In this post, I showed the step-by-step procedure to create and enable an IP-based and port-based virtual host on Apache web server. You can easily set up many domains on the same server.