VirtuaHost Directive

<VirtualHost> and </VirtualHost> are used to enclose a group of directives that will apply only to a particular virtual host - httpd.apache.org

If you are trying to debug your virtual host configuration, you may find the -S command line switch useful:

apachectl -S

This command will dump out a description of how Apache parsed the configuration file.

Whenever you add a new Apache Virtualhost file you should let Apache know to watch / index this file using:

a2ensite mypage1

where mypage1 is the path to the file you want to index. Finally always remember to:

service apache2 reload

# Description

Any directive that is allowed in a virtual host context may be used. When the server receives a request for a document on a particular virtual host, it uses the configuration directives enclosed in the <VirtualHost> section.

Addr can be any of the following, optionally followed by a colon and a port number (or *): - The IP address of the virtual host; - A fully qualified domain name for the IP address of the virtual host (not recommended); - The character *, which acts as a wildcard and matches any IP address. - The string _default_, which is an alias for *

<VirtualHost 10.1.2.3:80> ServerAdmin webmaster@host.example.com DocumentRoot "/www/docs/host.example.com" ServerName host.example.com ErrorLog "logs/host.example.com-error_log" TransferLog "logs/host.example.com-access_log" </VirtualHost>

Each Virtual Host must correspond to a different IP address, different port number, or a different host name for the server, in the former case the server machine must be configured to accept IP packets for multiple addresses. (If the machine does not have multiple network interfaces, then this can be accomplished with the ifconfig alias command. A ServerName should be specified inside each <VirtualHost> block. If it is absent, the ServerName from the "main" server configuration will be inherited. When a request is received, the server first maps it to the best matching <VirtualHost> based on the local IP address and port combination only. Non-wildcards have a higher precedence. If no match based on IP and port occurs at all, the "main" server configuration is used. If multiple virtual hosts contain the best matching IP address and port, the server selects from these virtual hosts the best match based on the requested hostname. If no matching name-based virtual host is found, then the first listed virtual host that matched the IP address will be used. As a consequence, the first listed virtual host for a given IP address and port combination is the default virtual host for that IP and port combination.

# See also - Apache VirtualHost