Apache related: One server, multiple DocumentRoots

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Apache related: One server, multiple DocumentRoots

Post 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?
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

...because virtual servers require unique IP-addresses, don't they???
cctrax
Forum Commoner
Posts: 36
Joined: Thu Jul 11, 2002 9:05 pm
Location: United States
Contact:

Post by cctrax »

true...
User avatar
mr_griff
Forum Commoner
Posts: 64
Joined: Tue Sep 17, 2002 11:11 am
Location: Bozeman, Montana

Post 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/
Post Reply