0

My server distribute two main websites, says : www.google.com & www.facebook.com (yeah I know :p)

I want them to be distributed via https. Using Apache, I defined a vhost file in sites-available/enabled containing this :

<VirtualHost *:80>
        ServerName google.com
        Redirect / https://www.google.com/
</VirtualHost>

<VirtualHost *:80>
        ServerName facebook.com
        Redirect / https://www.facebook.com/
</VirtualHost>

<VirtualHost *:80>
        DocumentRoot /srv/www/google/www/
        ServerName www.google.com
        ServerAlias www.facebook.com

        <Directory ... />
        # Google & Facebook points to the same directory (crazy right ?)

        # Next of the config
</VirtualHost>

<VirtualHost *:443>
        SSLEngine On
        SSLCertificateFile /path/to/google.crt
        SSLCertificateKeyFile /path/to/google.key

        DocumentRoot "/srv/www/google/www/"
        ServerName www.google.com

        <Directory .../>
        # Next of the config
</VirtualHost>

<VirtualHost *:443>
        SSLEngine On
        SSLCertificateFile /path/to/facebook.crt
        SSLCertificateKeyFile /path/to/facebook.key

        DocumentRoot "/srv/www/google/www/"
        ServerName www.facebook.com

        <Directory .../>
        # Next of the config
</VirtualHost>

BUT :

  • If I access to https://facebook.com, it fails saying that the SSL connection is not what expected : Google.com instead of facebook.com

Based on my configuration file, I understand why, so I tried to add :

<VirtualHost *:443>
        SSLEngine On
        ServerName facebook.com
        Redirect / https://www.facebook.com/
</VirtualHost>

But then, I can't even access facebook.com nor www.facebook.com via http/https.

So my question is quite simple : how can I redirect all https access to facebook.com (and eventually all sub facebooks : facebook.fr, www.facebook.fr, etc) to www.facebook.com (redirecting to www domain) in HTTPS ?

Thanks for your help ! :)

3 Answers 3

2

That's because you didn't configure a virtualhost for facebook.com, so apache picks the first configured one (www.google.com). What you're looking for is the ServerAlias configuration directive.

0

Unless you have SNI enabled (which doesn't work on IE on Windows XP), you can't host more than one SSL certificate on the same IP.

You can sometimes use a SAN certificate (sometimes called UCC) with both domains on it, but the way you're currently trying to do it just won't work.

0

The important thing to understand is that for HTTPS, the server SSL certificate is checked BEFORE the webserver is accessed. This means that the server SSL certificate must contain the names of all domains that are to be accessed on that IP address using Server Name Indication. As some clients do not support SNI, it's not unusual to use different IP addresses for different HTTPS sites in order to support them.

With the code you've given above, https://www.facebook.com will not work correctly and will give an SSL warning of incorrect certificate.

You must log in to answer this question.

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