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 current configuration for my website mail client:

    NameVirtualHost *:443

    <VirtualHost *:443>
            SSLEngine on
            SSLCertificateFile /etc/pki/tls/certs/ca.crt
            SSLCertificateKeyFile /etc/pki/tls/private/ca.key
            <Directory /var/www/mailclient>
                    AllowOverride All
            </Directory>
            DocumentRoot /var/www/mailclient
            ServerName mail.*
            ServerAlias mail.*
    </VirtualHost>

When i try to reach https:// mail.domain1.com or https:// mail.domain2.com this works fine.

But when i try to reach https:// domain1.com or https:// sub.domain1.com i still see the web mail client, but i dont want to see anything but a 404 or something like that. So how can i restrict this virtualHost only for a specific sub domain?

share|improve this question
add comment

2 Answers 2

up vote 0 down vote accepted

Configure a default vhost that will kick back an error. It needs to be above your current vhost in order to be default, but below the NameVirtualHost configuration.

NameVirtualHost *:443

<VirtualHost *:443>
    ServerName default.filler.name
    SSLEngine on
    SSLCertificateFile /etc/pki/tls/certs/ca.crt
    SSLCertificateKeyFile /etc/pki/tls/private/ca.key
    <Location />
        Order Allow,Deny
        Deny from all
    </Location>
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile /etc/pki/tls/certs/ca.crt
    SSLCertificateKeyFile /etc/pki/tls/private/ca.key
    <Directory /var/www/mailclient>
        AllowOverride All
    </Directory>
    DocumentRoot /var/www/mailclient
    ServerName mail.*
    ServerAlias mail.*
</VirtualHost>

It'll 403 instead of 404. Close enough?

share|improve this answer
    
That dit the trick, Thanks. –  Maikel May 18 '12 at 9:04
add comment

Apache will serve the default (*) vhost when it can't find the right one.
You could use a default vhost to get around this.

<VirtualHost _default_:443>
  RedirectMatch permanent ^/?(.*) http://mymainwebsite.com/$1
</VirtualHost>

This will prevent it from popping up if someone connects to port 443 with the IP or another subdomain.

share|improve this answer
    
When i put this code above my current VirtualHost i get an ssl_error_rx_record_too_long error which might indicate a loop. Im not sure what is going wrong? –  Maikel May 17 '12 at 21:06
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.