httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rainer Frey" <>
Subject Re: [users@httpd] dynamic/mass virtual hosts with www.* alias and localhost...
Date Fri, 08 May 2009 08:30:49 GMT
On Thursday 07 May 2009 16:08:01 wayne wrote:
> ahoy,

>     also, once dynamic/mass virtual hosting is enabled, i can no longer
> access the "default" site of localhost or  i have tried to
> use a VirtualHost directive to setup a default host (i.e. localhost),
> but with no luck.
>     i mainly will be using dynamic hosts, though i would like to have
> the default localhost site work (if possible) as well.  also, i was
> hoping to be able to customize certain dynamic virtual hosts with
> specific VirtualHost directives.

You need to understand that there is no localhost/ specific site in 
Apache. If the Server has different IP addresses, or Apache listens to 
different ports, the IP address and port to which the 
client connected are matched against the <VirtualHost> directives. 

If there is a matching NameVirtualHost directive for this address and port, 
the actual virtual Host is selected by the Name specified in the Host header, 
or if none matches, the first VHost with this address is used. As I mentioned 
before, NameVirtualHost does not work in the same context as mod_vhost_alias.

Otherwise, the VirtualHost is used directly. If no VHost matches address and 
port, but a VHost with the magic name _default_ exists for the port, that is 
used. If this also does not exist, the main server config is used.

At that point, you are now inside a VHost or the main server context. If 
within this context, a VirtualDocumentRoot is found, it is matched against 
the Host header to determine the document root and the server name. Otherwise 
theDocumentRoot and ServerName directives are used. Note that there is no 
fallback if VirtualDocumentRoot does not match, an error is returned instead. 
So you need to use seperate VHosts for the default site and the dynamic 

See and esp. for in-depth 

So you best remove all your configuration attempts, create a 
file /etc/apache2/sites-available/dynamic-vhosts with following content, and 
enable it with a2ensite dynamic-vhosts (assuming you do want to use the 
debian config):

UseCanonicalName Off
	VirtualDocumentRoot /var/web/sites/%-2.0.%-1/www
	VirtualScriptAlias /var/web/sites/%-2.0.%-1/cgi-bin

        <Directory /var/web>
                Order allow,deny
                Allow from all

Note that I used /var/web instead of /var/www to ensure that the dynamic sites 
do not overlap with the default document root. Otherwise all the sites would 
be available as subdirectories of the default site.

Now, on the IP address used for the dynamic sites, all those sites are 
available, and on any other IP (including localhost), the default site is 

Remember that you need to add the domain names for the site to DNS, not 
the /etc/hosts of the Apache server. Otherwise the clients can't resolve 
them :-)


The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message