Datasheet
“main” (Installation and Administration) — 2004/6/25 — 13:29 — page 548 — #574
i
i
i
i
i
i
i
i
22.10 Virtual Hosts
Using virtual hosts, host several domains with a single web server. In this
way, save the costs and administration workload for separate servers for
each domain. One of the first web servers that offered this feature, Apache
offers several possibilities for virtual hosts:
Name-based virtual hosts
IP-based virtual hosts
Operation of multiple instances of Apache on one machine
22.10.1 Name-Based Virtual Hosts
With name-based virtual hosts, one instance of Apache hosts several do-
mains. You do not need to set up multiple IPs for a machine. This is the eas-
iest, preferred alternative. Reasons against the use of name-based virtual
hosts are covered in the Apache documentation.
Configure it directly by way of the configuration file (/etc/apache2/
httpd.conf). To activate name-based virtual hosts, a suitable direc-
tive must be specified: NameVirtualHost *. * is sufficient to prompt
Apache to accept all incoming requests. Subsequently, the individual
hosts must be configured:
<VirtualHost *>
ServerName www.mycompany.com
DocumentRoot /srv/www/htdocs/mycompany.com
ServerAdmin webmaster@mycompany.com
ErrorLog /var/log/httpd/www.my.company.com-error_log
CustomLog /var/log/httpd/www.mycompany.com-access_log common
</VirtualHost>
<VirtualHost *>
ServerName www.myothercompany.com
DocumentRoot /srv/www/htdocs/myothercompany.com
ServerAdmin webmaster@myothercompany.com
ErrorLog /var/log/httpd/www.myothercompany.com-error_log
CustomLog /var/log/httpd/www.myothercompany.com-access_log common
</VirtualHost>
In the case of Apache 2, however, the paths of log files as shown in the
above example (and in any examples further below) should be changed
548
22.10. Virtual Hosts










