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 running a web server with Apache2 and several virtual domains. Also, there's a mail server for these domains, exposing a web interface. For each virtual domain example.com, I have the subdomain mail.example.com pointing to my webmail interface (Roundcube). It works nicely with the following configuration:

<VirtualHost *:80>
    ServerAdmin me@example.com
    ServerName mail.example.com
    ServerAlias mail.vname1.com, mail.vname2.com, mail.vname3.com, #...

    DocumentRoot /srv/www/mail/
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /srv/www/mail>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ErrorLog /var/log/apache2/mail.error.log
    LogLevel warn

    CustomLog /var/log/apache2/mail.access.log combined
</VirtualHost>

However, for each new customer, I have - among other things - to add the corresponding domain name to the list of ServerAliases.

Is there a way to automatically associate all mail.* subdomains with /srv/www/mail/?

share|improve this question
1  
ServerAlias supports wildcards - you should be able to use mail.* as a valid ServerAlias (although, I can't seem to find any evidence showing its use that way, it is commonly used the other way). I have used it in that format before for a number of common subdomains, but my VirtualHost block then contained a rewrite to a common URL - however, it since it was able to successfully capture the subdomain, it should work in your scenario. –  cyberx86 Dec 4 '11 at 1:34
    
cyberx86: Stupid me! What you suggested works perfectly. Post it as an answer, so I can accept it. –  Philip Dec 4 '11 at 9:28

1 Answer 1

up vote 5 down vote accepted

The ServerAlias directive supports wildcards - you should be able to use the following to match all the 'mail' subdomains.

ServerAlias mail.*

The wildcard subdomain (i.e. *.domain.tld) is well documented, but it is hard to find any indication that the domain part can be also be a wildcard.

I have used this approach quite often for common subdomains, when I used to use Apache. The only difference being that I used a redirect to a common URL (because I wanted to use SSL, and didn't want to get a certificate for every domain). None the less, it was able to successfully capture the subdomain, so the same implementation should work in your scenario. (Of course, you still need a static ServerName directive as well).

share|improve this answer

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.