ServerAlias without www not working on SSL virtualhost

5,484

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

VirtualHost *:443
    ServerAdmin [email protected]
    ServerName mydomain.com
    ...
/VirtualHost
VirtualHost *:443
    ServerAdmin [email protected]
    ServerName www.mydomain.com
    ...//same as above
/VirtualHost

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

Share:
5,484

Related videos on Youtube

didrocks66
Author by

didrocks66

Updated on September 18, 2022

Comments

  • didrocks66
    didrocks66 over 1 year

    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 [email protected]
            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

    • user9517
      user9517 about 8 years
      What is the exact, detailed error message your browser provides and are there any relevant messages in your logs.
    • didrocks66
      didrocks66 about 8 years
      The browser leads me to the root of my web server, basically bypassing the virtualhost. And what I posted the only relevant message in the logs (repeated each time apache is restarted)
    • Colt
      Colt about 8 years
      Is your "current and still valid SSL certificate" a multi-domain certificate covering both mydomain.com and mydomain.com?
  • tishma
    tishma over 7 years
    Eventually, found this one: serverfault.com/a/377842/61886 and it also provides some background on why it won't work.