Httpd Virtual Host Configuration: Difference between revisions
No edit summary |
|||
Line 18: | Line 18: | ||
The <tt><VirtualHost></tt> section must contain at minimum a <tt>[[httpd ServerName|ServerName]]</tt> directive to designate what host to serve and a <tt>[[httpd DocumentRoot |DocumentRoot]]</tt> directive to indicate the file system directory that contains the content to server. | The <tt><VirtualHost></tt> section must contain at minimum a <tt>[[httpd ServerName|ServerName]]</tt> directive to designate what host to serve and a <tt>[[httpd DocumentRoot |DocumentRoot]]</tt> directive to indicate the file system directory that contains the content to server. | ||
=Name-Based Virtual Host Resolution= | |||
When a request arrives, the server must find the best (most specific) matching <tt><VirtualHost></tt> configuration based on the IP address and the port the request came on. If just one <tt><VirtualHost></tt> is identified, that's the one that is used. If there is more than one virtual host that matches the IP:port, httpd will further compare the <tt>ServerName</tt> and <tt>ServerAlias</tt> directives to the value of the "Host" header arrived with the request. If no <tt>ServerName</tt>/<tt>ServerAlias</tt> match is found, then the first listed virtual host is used. | |||
=Configuration Inheritance= | =Configuration Inheritance= |
Revision as of 04:58, 6 January 2016
Internal
Overview
Virtual hosts can be declared using the <VirtualHost> configuration element. <VirtualHost> encloses a group of directives that apply to only a particular virtual host.
<VirtualHost ip:port> </VirtualHost>
Name-Based Virtual Host Configuration
For each virtual host you want to serve, create a <VirtualHost> section.
The <VirtualHost> section must contain at minimum a ServerName directive to designate what host to serve and a DocumentRoot directive to indicate the file system directory that contains the content to server.
Name-Based Virtual Host Resolution
When a request arrives, the server must find the best (most specific) matching <VirtualHost> configuration based on the IP address and the port the request came on. If just one <VirtualHost> is identified, that's the one that is used. If there is more than one virtual host that matches the IP:port, httpd will further compare the ServerName and ServerAlias directives to the value of the "Host" header arrived with the request. If no ServerName/ServerAlias match is found, then the first listed virtual host is used.
Configuration Inheritance
All directives present in the httpd configuration file above the <VirtualHost> section set up the values used by the "main" server, which responds to any requests that are not handled by a <VirtualHost> definition. These values also provide defaults for any <VirtualHost> containers that defined later in the file.
If any of these directives appear inside a <VirtualHost> container, their values override the "main" defaults.
Overridable directives:
Example
# # ... the "main" section # IncludeOptional conf.d/*.conf <VirtualHost> </VirtualHost> <VirtualHost> </VirtualHost>