From The Uniform Server Wiki
Revision as of 05:43, 20 April 2007 by Dimo414 (talk | contribs)
Jump to navigation Jump to search

VirtualHosts are usefull both for setting up Subdomains and for directing additional domains to your server. Put simply, they allow a (sub)domain to point to a different DocumentRoot.

httpd.conf File

At the bottom of the httpd.conf file, located in 'diskw\usr\local\apache2\conf', there is a commented out section on setting up VirtualHosts. It's relatively self explanatory, but to run down what you need to do, step by step: First, uncomment the line 'NameVirtualHost *'. Now, at the very end of the file, paste the following:

<VirtualHost *>
   DocumentRoot /www/example/foobar/
   ErrorLog logs/foobar-error_log
   CustomLog logs/foobar-access_log common
</VirtualHost >

To break down this example directive line by line:

  • <VirtualHost *> says the following is going to be a VirtualHost. The asterisk denotes any connection. If you wanted to limit the VirtualHost to just port 80 (the default HTTP port) you would instead type '<VirtualHost *:80>'.
  • ServerAdmin assigns an administrator email address to the domain.
  • DocumentRoot /www/example/foobar/ specifies the path to the document root. The domain you're setting up will point to this directory of the server.
  • ServerName is the domain name to use. Obviously, the domain must first be pointed to the Uniform Server.
  • ErrorLog logs/foobar-error_log and CustomLog logs/foobar-access_log common specify where error log files will be saved. You can put any directory you want, but a relativly logical naming convention is to put the (sub)domain before the title of the log, as done in this example.
  • </VirtualHost > ends the VirtualHost directive.

Repeat the <VirtualHost *> directive for each (sub)domain you wish to set up.