So, Apache supports VirtualHost — virtual hosts. It can, alone, from a single running instance and on a single IP and port, listen and serve different sites. In general, nothing extraordinary.
And each VirtualHost has its own settings. Where its directory is located, what it's called, what aliases it has, where to write logs, what the index file names are, etc.
But the thing is that admins sometimes need to specify parameters common to all VirtualHosts. Of course, these parameters can be overridden by settings inside the host itself, but, for example, specifying some default setting for ALL hosts is sometimes needed.
You wouldn't want to go through every VirtualHost and specify this setting in each one. And you also have to remember that webmasters and other admins create new hosts.
Common parameters for all VirtualHosts in Apache are specified... simply in the configuration file. The main thing is that these parameters must not be inside any blocks like "<Directory ...></Directory>" or "<VirtualHost ...></VirtualHost>" or anything like that. That is, you just declare the setting directly inside the config, and it's applied as the default setting for all VirtualHosts, while the virtual hosts themselves can override this setting within their own config.
Here's an example of such a setting: specifying where to put the log files for all sites. This is a piece of the Apache config, not the whole config:
...
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log
#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn
# Include module configuration:
Include mods-enabled/*.load
Include mods-enabled/*.conf
...
<VirtualHost *:80>
...
ErrorLog /www/myhost/error.log
</VirtualHost>
As we can see, here, in the general body of the config, it's specified that for all hosts logs should go to "${APACHE_LOG_DIR}/error.log", and in the config of one virtual host (below) it's defined that specifically this host's logs should go to another location: "/ww/myhost/error.log".
That is, the rule from the body of the config applies to everyone, and for specific hosts these settings can be overridden.
Applies to: Apache 2.x
Comments