Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I’m a beginner in working with apache and in need of your help. My task is to build a dynamic webserver (Debian 6.0.4, Apache 2.2, one public IP) which can host multiple websites and files (like pictures, pdf etc.) for preview purposes.

Now my problem is that I need two different document roots. One for the websites and the other one for the files.

My attempt is to use mod-vhost-alias, so I don’t need a new entry in the httpd.conf for every virtual host.

My httpd.conf looks like this:

UseCanonicalName Off
    Servername      *.
    VirtualDocumentRoot     /srv/www/%1/htdocs
<VirtualHost websites. >
   Servername      *.websites.
   VirtualDocumentRoot     /srv/www/websites/%1/htdocs

The first vhost serves the files and works fine. The second one should provide directories containing website data. The websites underneath the subdomain “websites” are only reachable, if I deactivate the first virtual host.

What do I have to do, to make both of them work at the same time?

If this topic is already dealt with please give me a link.

Thanks for your time and effort.

share|improve this question

You need to use ServerAlias instead of ServerName for the wildcard entries. ServerName doesn't support wildcards. But, you still should have a ServerName set.

Your <VirtualHost> definitions also need to match exactly to your NameVirtualHost directive.

Something along these lines:

    ServerAliast preview-vhost
    ServerName *
    VirtualDocumentRoot /srv/www/%1/htdocs
    ServerAlias websites-vhost
    ServerName *
    VirtualDocumentRoot /srv/www/websites/%1/htdocs
share|improve this answer
Hi Shane, thank you for your quick help! I followed your advises but I still can't reach any website from the second vhost. I always get a Error 404. What do you think of using two different ip addresses or two different webservers for the vhosts? – Larry Aug 8 '12 at 12:19
@Larry You could also do that, but there's really no reason that it shouldn't work just fine like this. Can you provide the output of apache2ctl -S? That should give us a good idea of what's going wrong. – Shane Madden Aug 8 '12 at 15:12

Your Answer


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.