From c85111fd920238e6af67bf01b86c7ab1402d4bab Mon Sep 17 00:00:00 2001
From: =?utf8?q?Andr=C3=A9=20Malo?=
This document describes when and how to use name-based virtual hosts.
- +This document describes when and how to use name-based virtual hosts.
IP-based virtual hosts use the IP address of the connection to - determine the correct virtual host to serve. Therefore you need to - have a separate IP address for each host. With name-based virtual - hosting, the server relies on the client to report the hostname as - part of the HTTP headers. Using this technique, many different hosts - can share the same IP address.
- -Name-based virtual hosting is usually simpler, since you need - only configure your DNS server to map each hostname to the correct - IP address and then configure the Apache HTTP Server to recognize - the different hostnames. Name-based virtual hosting also eases - the demand for scarce IP addresses. Therefore you should use - name-based virtual hosting unless there is a specific reason to - choose IP-based virtual hosting. Some reasons why you might consider - using IP-based virtual hosting:
- -IP-based virtual hosts use the IP address of the connection to + determine the correct virtual host to serve. Therefore you need to + have a separate IP address for each host. With name-based virtual + hosting, the server relies on the client to report the hostname as + part of the HTTP headers. Using this technique, many different hosts + can share the same IP address.
+ +Name-based virtual hosting is usually simpler, since you need + only configure your DNS server to map each hostname to the correct + IP address and then configure the Apache HTTP Server to recognize + the different hostnames. Name-based virtual hosting also eases + the demand for scarce IP addresses. Therefore you should use + name-based virtual hosting unless there is a specific reason to + choose IP-based virtual hosting. Some reasons why you might consider + using IP-based virtual hosting:
+ +Related Modules | Related Directives |
---|---|
To use name-based virtual hosting, you must designate the IP
- address (and possibly port) on the server that will be accepting
- requests for the hosts. This is configured using the NameVirtualHost
directive.
- In the normal case where any and all IP addresses on the server should
- be used, you can use *
as the argument to
- NameVirtualHost
. Note that mentioning an
- IP address in a NameVirtualHost
directive
- does not automatically make the server listen to that IP address. See
- Setting which addresses and ports Apache uses
- for more details. In addition, any IP address specified here must be
- associated with a network interface
- on the server.
The next step is to create a <VirtualHost>
block for
- each different host that you would like to serve. The argument to the
- <VirtualHost>
directive
- should be the same as the argument to the NameVirtualHost
directive (ie, an IP address,
- or *
for all addresses). Inside each <VirtualHost>
block, you will need at minimum a
- ServerName
directive to
- designate which host is served and a DocumentRoot
directive to
- show where in the filesystem the content for that host lives.
To use name-based virtual hosting, you must designate the IP
+ address (and possibly port) on the server that will be accepting
+ requests for the hosts. This is configured using the NameVirtualHost
directive.
+ In the normal case where any and all IP addresses on the server should
+ be used, you can use *
as the argument to NameVirtualHost
. Note that mentioning an
+ IP address in a NameVirtualHost
+ directive does not automatically make the server listen to that IP address.
+ See Setting which addresses and ports Apache uses
+ for more details. In addition, any IP address specified here must be
+ associated with a network interface on the server.
The next step is to create a <VirtualHost>
block for
+ each different host that you would like to serve. The argument to the
+ <VirtualHost>
directive
+ should be the same as the argument to the NameVirtualHost
directive (ie, an IP address,
+ or *
for all addresses). Inside each <VirtualHost>
block, you will need at minimum a
+ ServerName
directive to designate
+ which host is served and a DocumentRoot
+ directive to show where in the filesystem the content for that host
+ lives.
<VirtualHost>
block for the existing host.
- The ServerName
and
- DocumentRoot
included in this virtual
- host should be the same as the global ServerName
and DocumentRoot
. List this virtual host first in
- the configuration file so that it will act as the default host.
+ If you are adding virtual hosts to an existing web server, you
+ must also create a <VirtualHost>
block for the existing host. The ServerName
and DocumentRoot
included in this virtual host should be the
+ same as the global ServerName
and
+ DocumentRoot
. List this virtual
+ host first in the configuration file so that it will act as the default
+ host.
For example, suppose that you are serving the domain
- www.domain.tld
and you wish to add the virtual host
- www.otherdomain.tld
, which points at the same IP address.
- Then you simply add the following to httpd.conf
:
- NameVirtualHost *
-
- <VirtualHost *>
-
- ServerName www.domain.tld
- ServerAlias domain.tld *.domain.tld
- DocumentRoot /www/domain
-
- </VirtualHost>
-
- <VirtualHost *>
- ServerName www.otherdomain.tld
- DocumentRoot /www/otherdomain
-
- </VirtualHost>
-
You can alternatively specify an explicit IP address in place of
- the *
in both the NameVirtualHost
and <VirtualHost>
directives.
- For example, you might want to do this in order to run some name-based virtual
- hosts on one IP address, and either IP-based, or another set of name-based
- virtual hosts on another address.
Many servers want to be accessible by more than one name. This is
- possible with the ServerAlias
- directive, placed inside the <VirtualHost>
section. For
- example in the first <VirtualHost>
block above, the ServerAlias
directive indicates that the
- listed names are other names which people can use to see that same
- web site:
- ServerAlias domain.tld *.domain.tld
-
then requests for all hosts in the domain.tld
domain
- will be served by the www.domain.tld
virtual host. The
- wildcard characters *
and ?
can be used to match
- names. Of course, you can't just make up names and place them in ServerName
or ServerAlias
.
- You must first have your DNS server properly configured to map those names
- to an IP address associated with your server.
Finally, you can fine-tune the configuration of the virtual hosts
- by placing other directives inside the
- <VirtualHost>
containers.
- Most directives can be placed in these containers and will then change the
- configuration only of the relevant virtual host. To find out if a particular
- directive is allowed, check the Context of the
- directive. Configuration directives set in the main server
- context (outside any <VirtualHost>
container) will be used only if they
- are not overridden by the virtual host settings.
Now when a request arrives, the server will first check if it is
- using an IP address that matches the NameVirtualHost
. If it is, then it will look at
- each <VirtualHost>
- section with a matching IP address and try to find one where the
- ServerName
or
- ServerAlias
matches the requested hostname. If it finds one,
- then it uses the configuration for that server. If no matching virtual host
- is found, then the first listed virtual host that matches
- the IP address will be used.
As a consequence, the first listed virtual host is the
- default virtual host. The DocumentRoot
from the
- main server will never be used when an IP
- address matches the NameVirtualHost
- directive. If you would like to have a special configuration for requests
- that do not match any particular virtual host, simply put that configuration
- in a <VirtualHost>
- container and list it first in the configuration file.
For example, suppose that you are serving the domain
+ www.domain.tld
and you wish to add the virtual host
+ www.otherdomain.tld
, which points at the same IP address.
+ Then you simply add the following to httpd.conf
:
+ NameVirtualHost *
+
+ <VirtualHost *>
+
+ ServerName www.domain.tld
+ ServerAlias domain.tld *.domain.tld
+ DocumentRoot /www/domain
+
+ </VirtualHost>
+
+ <VirtualHost *>
+ ServerName www.otherdomain.tld
+ DocumentRoot /www/otherdomain
+
+ </VirtualHost>
+
You can alternatively specify an explicit IP address in place of the
+ *
in both the NameVirtualHost
and <VirtualHost>
directives. For example, you might want to do this
+ in order to run some name-based virtual hosts on one IP address, and either
+ IP-based, or another set of name-based virtual hosts on another address.
Many servers want to be accessible by more than one name. This is
+ possible with the ServerAlias
+ directive, placed inside the <VirtualHost>
section. For example in the first <VirtualHost>
block above, the
+ ServerAlias
directive indicates that
+ the listed names are other names which people can use to see that same
+ web site:
+ ServerAlias domain.tld *.domain.tld
+
then requests for all hosts in the domain.tld
domain will
+ be served by the www.domain.tld
virtual host. The wildcard
+ characters *
and ?
can be used to match names.
+ Of course, you can't just make up names and place them in ServerName
or ServerAlias
. You must
+ first have your DNS server properly configured to map those names to an IP
+ address associated with your server.
Finally, you can fine-tune the configuration of the virtual hosts
+ by placing other directives inside the <VirtualHost>
containers. Most directives can be
+ placed in these containers and will then change the configuration only of
+ the relevant virtual host. To find out if a particular directive is allowed,
+ check the Context of the
+ directive. Configuration directives set in the main server context
+ (outside any <VirtualHost>
+ container) will be used only if they are not overridden by the virtual host
+ settings.
Now when a request arrives, the server will first check if it is using
+ an IP address that matches the NameVirtualHost
. If it is, then it will look at each <VirtualHost>
section with a matching
+ IP address and try to find one where the ServerName
or ServerAlias
matches the requested
+ hostname. If it finds one, then it uses the configuration for that server.
+ If no matching virtual host is found, then the first listed virtual
+ host that matches the IP address will be used.
As a consequence, the first listed virtual host is the default
+ virtual host. The DocumentRoot
from
+ the main server will never be used when an IP
+ address matches the NameVirtualHost
+ directive. If you would like to have a special configuration for requests
+ that do not match any particular virtual host, simply put that configuration
+ in a <VirtualHost>
+ container and list it first in the configuration file.
Example configuration:
- NameVirtualHost 111.22.33.44
-
- <VirtualHost 111.22.33.44>
-
- ServerName www.domain.tld
- ServerPath /domain
- DocumentRoot /web/domain
-
- </VirtualHost>
-
What does this mean? It means that a request for any URI
beginning with "/domain
" will be served from the
diff --git a/docs/manual/vhosts/name-based.xml b/docs/manual/vhosts/name-based.xml
index 9a156caea5..08c651a25d 100644
--- a/docs/manual/vhosts/name-based.xml
+++ b/docs/manual/vhosts/name-based.xml
@@ -7,9 +7,7 @@
This document describes when and how to use name-based virtual hosts.
- +This document describes when and how to use name-based virtual hosts.
IP-based virtual hosts use the IP address of the connection to - determine the correct virtual host to serve. Therefore you need to - have a separate IP address for each host. With name-based virtual - hosting, the server relies on the client to report the hostname as - part of the HTTP headers. Using this technique, many different hosts - can share the same IP address.
- -Name-based virtual hosting is usually simpler, since you need - only configure your DNS server to map each hostname to the correct - IP address and then configure the Apache HTTP Server to recognize - the different hostnames. Name-based virtual hosting also eases - the demand for scarce IP addresses. Therefore you should use - name-based virtual hosting unless there is a specific reason to - choose IP-based virtual hosting. Some reasons why you might consider - using IP-based virtual hosting:
- -IP-based virtual hosts use the IP address of the connection to + determine the correct virtual host to serve. Therefore you need to + have a separate IP address for each host. With name-based virtual + hosting, the server relies on the client to report the hostname as + part of the HTTP headers. Using this technique, many different hosts + can share the same IP address.
+ +Name-based virtual hosting is usually simpler, since you need + only configure your DNS server to map each hostname to the correct + IP address and then configure the Apache HTTP Server to recognize + the different hostnames. Name-based virtual hosting also eases + the demand for scarce IP addresses. Therefore you should use + name-based virtual hosting unless there is a specific reason to + choose IP-based virtual hosting. Some reasons why you might consider + using IP-based virtual hosting:
+ +To use name-based virtual hosting, you must designate the IP
- address (and possibly port) on the server that will be accepting
- requests for the hosts. This is configured using the *
as the argument to
-
The next step is to create a *
for all addresses). Inside each
To use name-based virtual hosting, you must designate the IP
+ address (and possibly port) on the server that will be accepting
+ requests for the hosts. This is configured using the *
as the argument to
The next step is to create a *
for all addresses). Inside each
If you are adding virtual hosts to an existing web server, you
+ must also create a
For example, suppose that you are serving the domain
- www.domain.tld
and you wish to add the virtual host
- www.otherdomain.tld
, which points at the same IP address.
- Then you simply add the following to httpd.conf
:
You can alternatively specify an explicit IP address in place of
- the *
in both the
Many servers want to be accessible by more than one name. This is
- possible with the
then requests for all hosts in the domain.tld
domain
- will be served by the www.domain.tld
virtual host. The
- wildcard characters *
and ?
can be used to match
- names. Of course, you can't just make up names and place them in ServerAlias
.
- You must first have your DNS server properly configured to map those names
- to an IP address associated with your server.
Finally, you can fine-tune the configuration of the virtual hosts
- by placing other directives inside the
-
Now when a request arrives, the server will first check if it is
- using an IP address that matches the ServerAlias
matches the requested hostname. If it finds one,
- then it uses the configuration for that server. If no matching virtual host
- is found, then the first listed virtual host that matches
- the IP address will be used.
As a consequence, the first listed virtual host is the
- default virtual host. The
For example, suppose that you are serving the domain
+ www.domain.tld
and you wish to add the virtual host
+ www.otherdomain.tld
, which points at the same IP address.
+ Then you simply add the following to httpd.conf
:
You can alternatively specify an explicit IP address in place of the
+ *
in both the
Many servers want to be accessible by more than one name. This is
+ possible with the
then requests for all hosts in the domain.tld
domain will
+ be served by the www.domain.tld
virtual host. The wildcard
+ characters *
and ?
can be used to match names.
+ Of course, you can't just make up names and place them in ServerAlias
. You must
+ first have your DNS server properly configured to map those names to an IP
+ address associated with your server.
Finally, you can fine-tune the configuration of the virtual hosts
+ by placing other directives inside the
Now when a request arrives, the server will first check if it is using
+ an IP address that matches the ServerAlias
matches the requested
+ hostname. If it finds one, then it uses the configuration for that server.
+ If no matching virtual host is found, then the first listed virtual
+ host that matches the IP address will be used.
As a consequence, the first listed virtual host is the default
+ virtual host. The
Example configuration:
What does this mean? It means that a request for any URI
beginning with "/domain
" will be served from the
@@ -255,5 +247,3 @@
-
-
--
2.40.0