Name-Based Virtual Hosts
This is by far the preferred method of
managing virtual hosts, taking advantage of the ability of HTTP
1.1-compliant browsers (or at least browsers that support the
Host header . . . pretty much all of them at this
point) to send the name of the site they want to access. At
.../site.virtual/Name-based we have
www.butterthlies.com and sales.
butterthlies.com on 192.168.123.2. Of
course, these sites must have their names registered in DNS (or, if
you are dummying the setup as we did, included in
/etc/hosts). The Config file is as follows:
User webuser Group webgroup NameVirtualHost 192.168.123.2 <VirtualHost www.butterthlies.com> ServerName www.butterthlies.com ServerAdmin sales@butterthlies.com DocumentRoot /usr/www/APACHE3/APACHE3/site.virtual/htdocs/customers ErrorLog /usr/www/APACHE3/APACHE3/site.virtual/Name-based/logs/error_log TransferLog /usr/www/APACHE3/APACHE3/site.virtual/Name-based/logs/access_log </VirtualHost> <VirtualHost sales.butterthlies.com> ServerName sales.butterthlies.com ServerAdmin sales@butterthlies.com DocumentRoot /usr/www/APACHE3/APACHE3/site.virtual/htdocs/salesmen ServerName sales.butterthlies.com ErrorLog /usr/www/APACHE3/APACHE3/site.virtual/Name-based/logs/error_log TransferLog /usr/www/APACHE3/APACHE3/site.virtual/Name-based/logs/access_log </VirtualHost>
The key directive is
NameVirtualHost
, which tells Apache that requests to
that IP number will be subdivided by name. It might seem that the
ServerName directives play a ...