1

I'm confused as to how vhosts in Apache 2.4 work. I have enabled virtual hosts, and I have two websites set up on my server. I think that this means the default host (/var/www/html) doesn't work anymore. But which parts of httpd.conf are overrided by virtual hosts? Do the includes such as "conf.d" that are in httpd.conf apply to the virtual hosts or do I have to manually assign those? I have in httpd.conf a line which assigns a special header to RemoteIPHeader, do I have to include this line in each of my virtual host .conf files? Please help me understand how httpd.conf works when virtual hosts are enabled. Thanks!

6

Every Directive lists the context in which it is valid. In other words where it is allowed to be used.

The context can be any combination of:

s - server config This means that the directive may be used in the server configuration files (e.g., httpd.conf), but not within any <VirtualHost> or <Directory> containers. It is not allowed in .htaccess files at all.
v - virtual host This context means that the directive may appear inside <VirtualHost> containers in the server configuration files.
d - directory A directive marked as being valid in this context may be used inside <Directory>, <Location>, <Files>, <If>, and <Proxy> containers in the server configuration files, subject to the restrictions outlined in Configuration Sections.
h - .htaccess If a directive is valid in this context, it means that it can appear inside per-directory .htaccess files. It may not be processed, though depending upon the overrides currently active.

If a directive is used multiple times, both the context, the scope and the order the Directives are encountered determines which directive will have precedence.

With regards to VirtualHost entries the directives used there will override the default settings, but will only apply for that virtual host entry.

With name based virtual hosting the first <VirtualHost addr:port> becomes the default which will serve all requests that don't match any explicitly defined ServerName/ServerAlias names used in the other VirtualHost entries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.