From: Richard Bowen <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 /
+ <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.
If you are adding virtual hosts to an existing web server, you +
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.
+ the default host.
+ For example, suppose that you are serving the domain
www.domain.tld and you wish to add the virtual host
@@ -86,28 +88,36 @@
NameVirtualHost *
<VirtualHost *>
+
ServerName www.domain.tld
+ ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
+
</VirtualHost>
<VirtualHost *>
- ServerName www.otherdomain.tld
+ 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.
<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 if you add this to the first <VirtualHost> block
- above
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
+ ServerAlias domain.tld *.domain.tld
then requests for all hosts in the domain.tld domain
@@ -156,6 +166,13 @@
pages from the first virtual host listed for that IP address
(the primary name-based virtual host).
Host header as
+ required for name-based virtual hosts.
+ There is a possible workaround with the ServerPath
directive, albeit a slightly cumbersome one:
<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 /
+ <VirtualHost> block, you will need at minimum a
If you are adding virtual hosts to an existing web server, you
+ 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
@@ -115,28 +117,37 @@
NameVirtualHost *
<VirtualHost *>
+
+ ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
+
<VirtualHost *>
- ServerName www.otherdomain.tld
+
DocumentRoot /www/otherdomain
+
You can alternatively specify an explicit IP address in place of
the * in both the NameVirtualHost and
- <VirtualHost> directives.
<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
then requests for all hosts in the domain.tld domain
@@ -188,6 +199,13 @@
pages from the first virtual host listed for that IP address
(the primary name-based virtual host).
Host header as
+ required for name-based virtual hosts.
+ There is a possible workaround with the