1

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?

2 Answers 2

1

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?

0
2

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.

1
  • 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, 2012 at 21:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .