Ssl – ServerAlias without www not working on SSL virtualhost

apache-2.4sslssl-certificateubuntu-14.04virtualhost

I'm moving a site from a server to another, and using its current and still valid SSL certificate. The machine I'm working on is a Ubuntu 14.04 server. I've set up my usual virtual host file, let's call it my_domain.conf. These are its contents:

#omitting the major/minor signs near VirtualHost
VirtualHost *:443
        ServerAdmin webmaster@mydomain.com
        ServerName mydomain.com
        ServerAlias www.mydomain.com
        SSLEngine on
        SSLCertificateFile    /etc/ssl/certs/mydomain.com.crt
        SSLCertificateKeyFile /etc/ssl/private/mydomain.com.key
        DocumentRoot /var/www/html/mydomain.com/public
        ErrorLog /var/log/apache2/mydomain-error.log
        TransferLog /var/log/apache2/mydomain-access.log
/VirtualHost

Now, when I type www.mydomain.com on a browser, the VirtualHost works. But when I type mydomain.com, it doesn't. Both the customer and the webdesigner need it, so I can't avoid it.
I tried

  • Swapping ServerName and ServerAlias, and using only ServerName
  • Disabling all the other virtualhosts, including default ones
  • Adding SSLStrictSNIVHostCheck both on and the off after noticing this line on my general (not site specific) error.log: [ssl:warn] [pid 6558] AH02292: Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)

Nothing changed, and I really can't figure out why this is happening

EDIT: I forgot to add, by "it doesn't work" I mean the virtual host config file is bypassed and the browser takes me to the apache2 default document root

Best Answer

Same here. I gave up trying to make ServerAlias on SSL host. My solution:

VirtualHost *:443
    ServerAdmin webmaster@mydomain.com
    ServerName mydomain.com
    ...
/VirtualHost
VirtualHost *:443
    ServerAdmin webmaster@mydomain.com
    ServerName www.mydomain.com
    ...//same as above
/VirtualHost

I know it's ugly, but it works - no headache.

Related Topic