Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Apr 2005 07:26:46 -0500
From:      Duo <duo@digitalarcadia.net>
To:        Perttu Laine <plaine@gmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: apache vhost help.
Message-ID:  <426B9086.3030507@digitalarcadia.net>
In-Reply-To: <c6ef380c05042403587b5d349d@mail.gmail.com>
References:  <c6ef380c05042403587b5d349d@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Perttu Laine wrote:

>I have domain configured so *.domain.tld are A record to same IP. Now
>I have apache vhosts so www.domain.tld and domain.tld goes to apache
>data dir and webmail.domain.tld goes to webmail data dir.
>Problem is howto forward those all others to certain directory. s it
>possible to make *.domain.tld vhost to go in one dir. so anything else
>than domain.tld, www.domain.tld and webmail.domain.tld goes to like /www-data/somedir.
>
>One solution would be make that somedir to default root, but cannot
>use it 'cause I have other domains on same apache taht I have to
>handle differently.
>
>Someone known what I mean? Or even how to do this? :)
>
>  
>
Yes. It is quite simple.

Check out the following example, this is currently how I am setup.

I use a straight Bind directive:

BindAddress *

and then, we add the name directive:

NameVirtualHost *

Then, we can add as many hostnames (provided they have a domain record. 
They MUST have a valid domain record. Either an A or an Alias)

 <VirtualHost *>
    ServerName www.domain1.com
    DocumentRoot /path/to/first/dir
    </VirtualHost>

    <VirtualHost *>
    ServerName www.domain2.net
    DocumentRoot /a/different/pathname
    </VirtualHost>

Now, we get freaky.

    <VirtualHost *>
    ServerName duo.domain2.net
    DocumentRoot /path/to/my/home/dir/duo
    </VirtualHost>

    <VirtualHost *>
    ServerName someonelse.domain1.com
    DocumentRoot /path/to/entirely/different/place
    </VirtualHost>

Now, in the above example, my main server Document Root is the same as 
my Virtual host for www.domain2.net. As long as you have legal 
hostnames, you can define them as a Virtual Host. Name based Virtual 
hosting is well described in the apache manual. As it relies mostly on 
the browser telling the server what name its looking for.

Try it and test. Make a copy of your httpd.conf and play a bit. =)

-- 
Duo.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?426B9086.3030507>