HomeApache Page 4 - Configuring and Using Virtual Hosts in Apache
Find File System Called Hosts - Apache
Begin creating and managing virtual hosts with Apache with this clear explanation from Dan Wellman. He explains what virtual hosts are and illustrates a basic way of setting up virtual hosts.
I have shown you only the most basic way of setting up virtual hosts; you can use almost any directive inside a <VirtualHost> container, and these directives will override or work alongside the equivalent directive in the main server configuration.
The only limit to how many virtual hosts you can create are the limitations of the physical machine that Apache is running on. Apache uses file descriptors, integers denoting files that are open, for any log files, in addition to another twenty used by the server itself. On most UNIX platforms, the limit to the number of file descriptors in use is 64, which can be used up very quickly. Changes to the configuration of the operating system can increase this, but a more suitable solution is not using the ErrorLog or TransferLog directives within the <VirtualHost> blocks, which will make Apache write only to the main hosts log files and therefore reduce the number of log files in use. Additionally, some operating systems will need to have an extra network interface card for each IP address.
If you are using Apache on a Windows XP desktop PC, for testing PHP or CGI for example, you now need to find a system file called hosts, which will be under the following path: C:WINDOWSsystem32driversetc. Open the file with Notepad and you should see something like this:
# space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host 127.0.0.1 site1 site2
The IP Address for a local host is always 127.0.0.1. To make it work you just need to add the virtual host name to the same line as the main host name, separated by a tab-space. This is similar to mapping your server's DNS settings.
You should now have enough information to begin creating and managing virtual hosts with Apache. There are many configurations that can be used, so experiment until you find one that matches your particular needs.