0

My Ubuntu server has this in /etc/apache2/sites-enabled/002-foosite

<VirtualHost 72.14.xxx.yyy:80>
    ServerName foosite.com
    ServerAlias www.foosite.com
    DocumentRoot /home/bar/public_html
    ServerAdmin bar@gmail.com
</VirtualHost>

Everytime I go to my server's port 80, I get the contents of /home/bar/public_html. But what I want to do is have more than one DocumentRoot based on the URL the user accesses. For example:

http://server/bar should go have DocumentRoot /home/bar/public_html
http://server/pligg should have DocumentRoot /srv/www/pligg
http://server/~blah should have DocumentRoot /home/blah/public_html

I'm sure this is not an uncommon setup, but I don't really understand the differences between Alias, VirtualHost, NameVirtualHost and all the other settings to configure this. How can I do this?

Thanks!

2 Answers2

9

A namevirtualhost is where you have different websites on different hostnames, but with the same ip address. For example, if server1.com and server2.com both had the same ip address, you would use a namevirtualhost for this.

Virtualhosts can also be seperated by ip addresses, in the case that server1.com and server2.com had different addresses.

An alias would be used in the case of the http://server/pligg example which you posted, to link a directory that is otherwise elsewhere located (usually outside the document root). Inside a <VirtualHost> container the alias will apply just for that virtualhost. If placed outside it the alias will work for all virtualhosts.

Alias /pligg/ "/srv/www/pligg/"

<Directory "/srv/www/pligg">
    Order allow,deny
    Allow from all
</Directory>

http://server/~blah, where blah is a user and the location is in blah's home directory should be confgured with userdir. To enable userdir (on debian/ubuntu apache) you can use the 'a2enmod' script eg. a2enmod user_dir.

theotherreceive
  • 8,365
  • 1
  • 31
  • 44
2

This should do it

<VirtualHost 72.14.xxx.yyy:80>
  ServerName foosite.com
  ServerAlias www.foosite.com
  DocumentRoot /home/bar/public_html
  Alias /bar/ /home/bar/public_html
  Alias /pligg/ /srv/www/pligg
  Userdir public_html
  ServerAdmin bar@gmail.com
</VirtualHost>

For the alias command, see the mod_alias docs. For the ~ magic, see the mod_userdir docs or this public html howto.

Brian De Smet
  • 1,139
  • 7
  • 10
  • Thanks for the suggestion, but the Alias directive gives this message in the error_log: [Mon Jul 06 20:48:58 2009] [error] [client 76.79.xxx.yyy] File does not exist: /home/bar/public_html/pligg Looks like it's still thinking "inside" /home/bar/public_html - something else I can try? –  Jul 07 '09 at 00:53