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.

Is there a way to setup a catchall (for subdomains) virtual server for a single domain, where I have a couple pre-defined subdomains.

ie:

webmail.example.com -> points to "/var/web/roundcube"

beta.example.com -> points to "/var/web/beta/"

example.com and all other subdomains -> point to "/var/web/www"

<VirtualHost *:80>
    ServerName webmail.example.com
    ServerAdmin webmaster@example.com

    DocumentRoot /var/web/roundcube
    <Directory /var/web/roundcube/>
        ...
    </Directory>
...
</VirtualHost>

<VirtualHost *:80>
    ServerName beta.example.com
    ServerAdmin webmaster@example.com

    DocumentRoot /var/web/beta
    <Directory /var/web/beta/>
        ...
    </Directory>
...
</VirtualHost>

<VirtualHost *:80>
    ServerName example.com
    ServerAlias *.example.com
    ServerAdmin webmaster@example.com

    DocumentRoot /var/web/www
    <Directory /var/web/www/>
        ...
    </Directory>
...
</VirtualHost>
share|improve this question
1  
Your config should do just that. What problem are you having? –  Shane Madden Aug 6 '13 at 23:13
    
My question is, is this the proper way to do it, and in what order does it get loaded (if say each are in separate config files), does the wildcard take precedence if it is loaded first? Or is there a better / more appropriate way to do the above? Sorry I didn't make that very clear when I asked the question. –  Aaron Murray Aug 6 '13 at 23:17

1 Answer 1

up vote 2 down vote accepted

That should work just fine, and this is definitely the proper way to do what you're trying to do!

  • Load order doesn't matter in your example, since these virtual hosts cover all the domains you're serving content for.
    • An exact match to a ServerName or ServerAlias will trump a wildcard ServerAlias, regardless of the order they were loaded in.
    • The load order matters for requests which don't match any of the ServerName or ServerAlias directives in any way (say, with the IP in the URL instead of hostname) - those requests will be served by the first virtual host to load.
share|improve this answer
    
that clarifies it perfectly for me thank you –  Aaron Murray Aug 7 '13 at 6:33

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.