Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Ok, so here's my problem: I've set up myself a virtualhost with an appropriate server name. I also have, for example, Squirrelmail and SVN installed on the same machine. I want to get to the default page by typing http :// mydomain , get to my mail frontend by typing http ://mydomain /mail and to my svn by typing http :// mydomain.no-ip.org /svn.

Heres my vhost definition:

<VirtualHost *:80>

ServerName mydomain.no-ip.org

#Default site, accessible by http :// mydomain.no-ip.org/
<Location />
    DocumentRoot "/var/www/alias"   
    DirectoryIndex index.php
</Location> 

#Squirrelmail, accessible by http :// mydomain.no-ip.org /mail  
<Location /mail>
    DocumentRoot /usr/share/squrrelmail     
    Options FollowSymLinks
    <IfModule mod_php5.c>
            php_flag register_globals off
    </IfModule>
    <IfModule mod_dir.c>
         DirectoryIndex index.php
    </IfModule>
    <Files configtest.php>
            order deny,allow
            deny from all
            allow from 127.0.0.1
    </Files>
</Location>

#SVN, accessible by http :// mydomain.no-ip.org /svn
<Location /svn>
    DAV svn
    SVNParentPath "/svnrepo"
    SVNListParentPath On
    AuthType Basic
    AuthName "My SVN Repo"
    AuthUserFile "/svnrepo/htpasswd"
    Require valid-user
</Location>

However, there's a problem with that one; when trying to restart apache, it says that you can't define a DocumentRoot within a Location. Therefore, there's something that I'm doing wrong, but I don't yet know what exactly.

When browsing serverfault to find if anybody had a similar problem, I've found a link to Apache's vhost examples: http://httpd.apache.org/docs/2.0/vhosts/examples.html , hovever, I can't figure out which example would be the best one there.

To be honest, neither am I versed in apache and it's ways, so I know what I've just written may be, to you, nonsensical at best.

So, anybody knows how to solve my problem, please? Any help would be greatly appreciated!

share|improve this question
add comment

2 Answers 2

Indeed, you cannot have another DocumentRoot; you'll want an Alias instead.

Drop the DocumentRoot from the <Location> block, and replace it with this (which must be outside the <Location> block):

Alias /mail /usr/share/squrrelmail

And let's apply those SquirrelMail settings to the directory instead of the location; just swap out the definitions at the top and bottom of the block:

<Directory /usr/share/squrrelmail>
    Options FollowSymLinks
    <IfModule mod_php5.c>
            php_flag register_globals off
    </IfModule>
    # etc
</Directory>

Also, it's unlikely that there's any permissions settings anywhere that apply to the SquirrelMail directory. You'll probably need this or similar in the <Directory /usr/share/squrrelmail> section:

Order Allow,Deny
Allow from all
share|improve this answer
    
"And let's apply those SquirrelMail settings to the directory instead of the location" - SquirrelMail can be in Location container –  Lazy Badger Feb 23 '12 at 23:44
1  
@LazyBadger Sure - but since it maps directly to a directory location, it's a cleaner config and, well, recommended: When applying directives to objects that reside in the filesystem always use <Directory> or <Files>. –  Shane Madden Feb 24 '12 at 0:37
    
Guys, see the "What to use When" section at httpd.apache.org/docs/2.2/sections.html for a full explanation of Directory, Files and Location and when each best apply. –  Yanick Girouard Feb 24 '12 at 1:39
    
@YanickGirouard Yes - that's the page that I quoted and linked in my last comment. –  Shane Madden Feb 24 '12 at 1:45
    
Woops, I didn't realize it was a link... Sorry then! –  Yanick Girouard Feb 24 '12 at 1:47
show 2 more comments
  1. Don't use virtualhosts for single host, configure "Man server" part
  2. Read about Alias directive
share|improve this answer
1  
Why shouldn't you use a virtual host for a single-site server? Do you have any evidence that it does soothing related to performance or anything else? I ask, because it is far easier to add a second virtual host next month, when you find out you have to support an additional domain, if you already have virtual hosting setup. –  Zoredache Feb 24 '12 at 0:11
    
@Zoredache - because "Okkam Razor" exist. And when and if I'll want virtualhosts, I'll just add mod_vhost_alias instead of VirtualHost containers headache –  Lazy Badger Feb 24 '12 at 0:23
    
@LazyBadger Huh? mod_vhost_alias only covers a tiny, tiny subset of the use cases for vhosts. –  Shane Madden Feb 24 '12 at 0:39
    
I don't think Occam's razor really applies here it is about finding a simple explanation. On many Linux distributions the default configurations use virtual hosts by default (Debian-based). On those distros it would be more work, to remove all the virtual hosting config, and if you did, then your configuration would diverge from the package quite a bit making upgrading more difficult. A pragmatic approach would be to not work against how your distro does things by default unless you have a good reason. –  Zoredache Feb 24 '12 at 0:40
    
Lazy badger is right, there's no point in using virtual hosts for a single server unless you are planing on adding multiple domains later and you want to allow for expansion that way. Use aliases, that's all you need really. Doing what you're doing now is like having one host with a single virtual guest on it when you know there won't ever be any more on it. –  Yanick Girouard Feb 24 '12 at 1:33
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.