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 have a web application that needs to support custom domains, in that regard I have set-up the following name based virtual server:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias * *.example.com www.example.com example.com
    RailsEnv production
    RackEnv production
    DocumentRoot /srv/www/example/current/public
    <Directory /srv/www/example/current/public>
             AllowOverride all
             Options -MultiViews FollowSymLinks
    </Directory>
    ErrorLog /srv/www/example/log/error.log
    TransferLog /srv/www/example/log/access.log
</VirtualHost>

Notice the * as the server alias? that catches all the domains on that server. However, I have other sites on this server which I want to be excluded from this list. It is more economical for me to have a list of excluded domains than manually set every domain a user may register with at this service as a serverAlias...

Perhaps this is not the best way to go, but I'm looking for help, in the best (relatively simple) way to set up a web-app that may catch any domains, while allowing other specific domains to be routed to different apps.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Apache searches for a match in the order that the domains are defined. If I understand you problem correctly then it can be solved by defining your hosts to be excluded before the catch all host.

<VirtualHost *:80>
    ServerName excluded.example.com
    ServerAlias  something.example.com ...
    ...
</VirtualHost>
<VirtualHost *:80>
    ServerName example.com
    ServerAlias * *.example.com www.example.com example.com
    RailsEnv production
    ...
</VirtualHost>
share|improve this answer
1  
Yes, you are right, but I am puzzled about how to do this on a default Ubuntu 10.4 stack, where the whole shenanigans is managed by having a sites-available and sites-enabled directories, and each virtual host definition exists in its own exclusive file... how do I control the order in that case? –  Victor S Nov 20 '11 at 2:10
    
The files are loaded in alphabetic order (the default sort order for ls). –  Iain Nov 20 '11 at 8:22
    
for a site definition that needs to come first, name it something like 000-excluded.example.com.conf in the sites-available dir. –  Brian Minton Aug 15 at 13:55

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.