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 127.0.0.1.  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/127.0.0.1 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 
VHosts.

See http://httpd.apache.org/docs/2.2/vhosts/ and esp. 
http://httpd.apache.org/docs/2.2/vhosts/details.html for in-depth 
explanation.

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
<VirtualHost ip.address.where.yourvhost.domains.point.to>
        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
        </Directory>
</VirtualHost>
--------

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 
served.

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 :-)

HTH
Rainer



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
   "   from the digest: users-digest-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org

Reply via email to