Have you ever wondered how ISPs and web service hosts could use one physical server to have many hostnames? Apache, the popular Web server for Linux and Unix, allows you to host virtual hostnames with multiple IP addresses. You can set one IP to each hostname, but it also allows you to host multiple hostnames on a single IP.
To do this first identify your web server’s IP address. Use ipconfig for example to determine the IP address using Windows command line:
Open the httpd-vhosts.conf configuration file inside the apache/conf/extra folder and add the following lines:
second.hostname.com 192.168.1.101
Replace 192.168.1.101 and second.hostname.com with your real IP address and hostname. This will allow Apache to know which IP it should serve the virtual hostname. Afterwards, add the following lines:
<VirtualHost *:80>
ServerAdmin postmaster@second.hostname.com
DocumentRoot “C:/xampp/htdocs/second.hostname.com”
ServerName second.hostname.comServerAlias www.dummy-host.localhost
ErrorLog “logs/second.hostname.com-error.log”
CustomLog “logs/second.hostname.com-access.log” combined
</VirtualHost>
This will add second.hostname.com in your list of virtual hosts and serve the pages in the document root. Make sure that the hostname points to the IP address – check your DNS settings. Put the webpages that you want to be hosted on this hostname on the path value of DocumentRoot. In the example above, “C:/xampp/htdocs/second.hostname.com”. This will be different in your host.
Lastly, restart Apache then browse the hostname in your browser to test. In the example below I am using a XAMPP control panel to restart Apache – it might be different if you are using another Apache controller.
I hope this gets you started with hosting multiple hostnames in a single apache instance. Later I will show how to add virtual hosts using Apache’s rival, Microsoft’s IIS.
Ben Carigtan shows you how it’s done!







Be The First To Comment
Please Leave Your Comments Below