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.

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
NameVirtualHost 192.168.10.45
<VirtualHost preview.example.com>
    Servername      *. preview.example.com
    VirtualDocumentRoot     /srv/www/%1/htdocs
</VirtualHost>
<VirtualHost websites. preview.example.com >
   Servername      *.websites. preview.example.com
   VirtualDocumentRoot     /srv/www/websites/%1/htdocs
</VirtualHost>

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
add comment

1 Answer

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:

NameVirtualHost 192.168.10.45:80
<VirtualHost 192.168.10.45:80>
    ServerAliast preview-vhost
    ServerName *.preview.example.com
    VirtualDocumentRoot /srv/www/%1/htdocs
</VirtualHost>
<VirtualHost 192.168.10.45:80>
    ServerAlias websites-vhost
    ServerName *.websites.preview.example.com
    VirtualDocumentRoot /srv/www/websites/%1/htdocs
</VirtualHost>
share|improve this answer
1  
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
add comment

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.