4.2.3. Mixed Name/IP-Based Virtual Hosts
You
can, of course, mix the two techniques.
<VirtualHost> blocks that have been
NameVirtualHost edwill
respond to requests to named servers; others will respond to requests
to the appropriate IP numbers. This will also be important when we
look at Apache SSL (see Chapter 11):
User webuser
Group webgroup
NameVirtualHost 192.168.123.2
<VirtualHost www.butterthlies.com>
ServerAdmin sales@butterthlies.com
DocumentRoot /usr/www/APACHE3/APACHE3/site.virtual/htdocs/customers
ErrorLog /usr/www/APACHE3/APACHE3/site.virtual/IP-based/logs/error_log
TransferLog /usr/www/APACHE3/APACHE3/site.virtual/IP-based/logs/access_log
</VirtualHost>
<VirtualHost 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/IP-based/logs/error_log
TransferLog /usr/www/APACHE3/APACHE3/site.virtual/IP-based/logs/access_log
</VirtualHost>
<VirtualHost 192.168.123.3>
ServerAdmin sales@butterthlies.com
DocumentRoot /usr/www/APACHE3/APACHE3/site.virtual/htdocs/salesmen
ServerName sales-IP.butterthlies.com
ErrorLog /usr/www/APACHE3/APACHE3/site.virtual/IP-based/logs/error_log
TransferLog /usr/www/APACHE3/APACHE3/site.virtual/IP-based/logs/access_log
</VirtualHost>
The two named sites are dealt with by the
NameVirtualHost directive, whereas requests to
sales-IP.butterthlies.com, which we have set up
to be192.168.123.3, are dealt with by the third
<VirtualHost> block. It is important that
the IP-numbered VirtualHost block comes last in
the file so that a call to it falls through the named blocks.
This is a handy technique if you want to put a web site up for
access — perhaps for testing — by outsiders, but you
don't want to make the named domain available.
Visitors surf to the IP number and enter your private site. The
ordinary visitor is very unlikely to do this: she will surf to the
named URL. Of course, you would only use this technique for sites
that were not secret or compromising and could withstand inspection
by strangers.