Page 1 of 1

Apache related: One server, multiple DocumentRoots

Posted: Sun Nov 03, 2002 6:30 pm
by Heavy
I wonder if there is any way to configure Apache to have one server, for example:

Code: Select all

ServerName   home.localdomain
And have sub-sites accessible with Aliases, for example:

Code: Select all

Alias /site-1/     /var/www_pub/site-1/
Alias /site-2/     /var/www_pub/site-2/
Alias /site-3/     /var/www_pub/site-3/
...and then have a unique DocumentRoot path for each sub-site?

Why then?
Well, I have several PHP-projects on my box and don't want to set up a virtual server for each PHP-project that is relying on a unique configured DocumentRoot.

Anyone?
Or is there a better way to line up things that I didn't think of?

Posted: Sun Nov 03, 2002 6:32 pm
by Heavy
...because virtual servers require unique IP-addresses, don't they???

Posted: Thu Nov 14, 2002 9:26 am
by cctrax
true...

Posted: Thu Nov 14, 2002 10:13 am
by mr_griff
You can setup name-based virtual servers to use one IP address. Then all you have to do is have a DNS entry for each domain pointing to the one IP address. Or if this is just something you are testing at home, you can put these entries in your HOSTS file. Apache looks at the domain name and matches it to one of the name-based virtual servers for that IP address. If no match is found it uses the first one.

The Apache settings (httpd.conf) would be similar to this:

Code: Select all

NameVirtualHost 192.168.0.2  # <-- your servers IP address here

<VirtualHost 192.168.0.2>
    ServerAdmin webmaster@mydomain.com
    DocumentRoot /var/www_pub/site-1/
    ServerName site1.mydomain.com
</VirtualHost>

<VirtualHost 192.168.0.2>
    ServerAdmin webmaster@mydomain.com
    DocumentRoot /var/www_pub/site-2/
    ServerName site2.mydomain.com
</VirtualHost>
You can find some official documentation here: http://www.apache.org/docs/vhosts/