Defining a Virtual Host

# VirtualHost for <VirtualHost *>

ServerName DocumentRoot /srv/www/vhosts/wiley-bible ErrorLog /var/log/apache2/wiley-bible-error_log CustomLog /var/log/apache2/wiley-bible-access_log combined <Directory "/srv/www/vhosts/wiley-bible"> Order allow.deny Allow from all </Directory> </VirtualHost>

This virtual host operates on the same IP address as the default server. It depends on the fact that DNS gives the same IP address for the host as it does for the name associated with the default server (the real host name of the server machine). When an HTTP request comes in for http://www.wiley-bi''ndex.html, the fact that the HTTP request header specifies the host tells the Apache server that the page it needs to serve is /srv/www/vhosts/wiley-bible/index.html rather than the default /srv/www/htdocs/index.html.

If you have multiple virtual hosts you should add a line to the file /etc/apache2/listen .conf:

NameVirtualHost *

Then each virtual host declaration should start with:

<VirtualHost *>

You can be more specific and replace the * by the IP address and port number but this is not necessary for a simple, name-based virtual hosts configuration.

i- : i , There is good information about setting up virtual hosts in the official Apache r1^** documentation at

/name-based.html. A common problem reported is that the default server ''goes away'' when a virtual host is first defined. Once you have defined a name-based virtual host, you must add the default server as a virtual host also. Otherwise, you will see the first virtual host when you access the server by its default name.

f You can test your virtual host configuration with the command apache2ctl -S. This will report on the virtual hosts that are visible when the configuration you have written becomes active.

Was this article helpful?

0 0

Post a comment