Archive for the ‘Uncategorized’ Category
Aim: To create and use virtual hosts and domain name as www.audio2.local
What is Virtual Host
The term Virtual Host refers to the practice of maintaining more than one server on one machine, as differentiated by their apparent hostname.
For example, it is often desirable for companies sharing a web server to have their own domains, with web servers accessible as http://www.company1.com and http://www.company2.com, without requiring the user to know any extra path information.
Virtual Hosts can be configured in two ways
- · Name-based Virtual Hosts
- · IP-based Virtual Hosts
Name-based vs. IP-based Virtual Hosts
IP-based virtual hosts use the IP address of the connection to determine the correct virtual host to serve. Therefore you need to have a separate IP address for each host. With name-based virtual hosting, the server relies on the client to report the hostname as part of the HTTP headers. Using this technique, many different hosts can share the same IP address.
Name-based virtual hosting is usually simpler, since you need only configure your DNS server to map each hostname to the correct IP address and then configure the Apache HTTP Server to recognize the different hostnames.
Name Based Virtual Host Configuration
To use name-based virtual hosting, you must designate the IP address on the server that will be accepting requests for the hosts. This is configured using the NameVirtualHost directive.
The next step is to create a <VirtualHost> block for each different host that you would like to serve. The argument to the <VirtualHost> directive should be the same as the argument to the NameVirtualHost directive.
Inside each <VirtualHost> block, you will need at minimum a ServerName directive to designate which host is served and a DocumentRoot directive to show where in the filesystem the content for that host lives.
If you are adding virtual hosts to an existing web server, you must also create a <VirtualHost> block for the existing host. The ServerName and DocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot.
To create domain as www.audio2.local
Open file “httpd-vhosts” at location C:\xampp\apache\conf\extra\httpd-vhosts
Add following lines to end of document
NameVirtualHost 127.0.0.1:80 <VirtualHost 127.0.0.1:80> DocumentRoot C:/xampp/htdocs ServerName localhost </VirtualHost> <VirtualHost 127.0.0.1:80> DocumentRoot C:/xampp/htdocs/audio2 ServerName www.audio2.local </VirtualHost>
“audio2” is the name of my web application folder on my localhost, htdocs folder.
Save and exit.
Open Notepad in Administrator Mode by, right clicking and selecting “Run as” administrator.
Open the hosts file at location C:\Windows\System32\drivers\etc\hosts in note pad.
Make sure u make the backup file, which will help you, in case anything goes wrong.
Add following code to end of hosts file
127.0.0.1 localhost 127.0.0.1 www.audio2.local
Save the file and exit
Make sure you restart apache server.
Type http://www.audio2.local in browser url field (i.e. your domain name to open website instead of typing localhost)
IF ANY PROBLE OCCURS AND APACHE SERVER DOESNT START AFTER CONFIGURATIONS, UNDO ANY CHANGES DONE TO FILE IN C:\xampp\apache\conf\extra\httpd-vhosts, YOUR SERVER WILL START AGAIN.