8

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!

pjmorse
  • 1,550
  • 1
  • 17
  • 34
user905747
  • 193
  • 1
  • 2
  • 4

2 Answers2

17

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
Shane Madden
  • 114,520
  • 13
  • 181
  • 251
  • "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 or .`](http://httpd.apache.org/docs/current/sections.html) – Shane Madden Feb 24 '12 at 00:37
  • Guys, see the "What to use When" section at http://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 01:39
  • @YanickGirouard Yes - that's the page that I quoted and linked in my last comment. – Shane Madden Feb 24 '12 at 01:45
  • Woops, I didn't realize it was a link... Sorry then! – Yanick Girouard Feb 24 '12 at 01:47
  • @YanickGirouard No worries! It's definitely hard to see which text is a link with that gray background and no underline. – Shane Madden Feb 24 '12 at 01:54
  • If you're using Passenger with Ruby On Rails, you'll need to add: PassengerEnabled off – Isaac Betesh Apr 16 '13 at 21:33
-2
  1. Don't use virtualhosts for single host, configure "Man server" part
  2. Read about Alias directive
Lazy Badger
  • 3,137
  • 15
  • 13
  • 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 00: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 00:23
  • @LazyBadger Huh? `mod_vhost_alias` only covers a tiny, tiny subset of the use cases for vhosts. – Shane Madden Feb 24 '12 at 00:39
  • I don't think [Occam's razor](http://en.wikipedia.org/wiki/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 00: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 01:33
  • @Zoredache - I said about **common**, not binded to *some cases* situation and workstyle. About "...A pragmatic approach would be to not work against how your distro does things by default..." I tend to agree, but it's alsp Occam Razor - Don't trouble trouble unsless trouble troubles you. In OP situation - he has more headache with virtualhosts, than needed to have *task solved* – Lazy Badger Feb 24 '12 at 01:45
  • Yes, that's the reason why it's a vhost: The fact that 'now' it's hosting only one page doesn't mean that there won't be any other pages hosted 'later'. Therefore, it's configured as vhost. Thanks anyway! – user905747 Feb 24 '12 at 08:26