1

I am able to serve http://www.domain.com and http://domain.com. Also https://domain.com works fine too. But not https://www.domain.com for some reason this doesn't work. I even created a www.domain.com in my sites-availible folder and also enabled it. I reloaded the configuration and yet it still doesn't work.

I have a wildcard certificate so that is NOT the problem.

    <IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin admin@domain.com
        ServerName *.domain.com:443
        ServerAlias www.domain.com
        VirtualDocumentRoot /var/www/%0

Thanks for any help.

  • If you have a wildcard certificate for *.domain.com, then calls to domain.com should be giving you browser warnings of a certificate mismatch, since *.domain.com doesn't match domain.com. – Mike Scott Jan 21 '14 at 21:00
1

To have the same site listening on both HTTP and HTTPS you will need 2 virtual hosts, one for SSL and one for normal connections.

Remove :443 from your "ServerName" parameter.

I just created a config doing what you request here, in my test environment, and this is what I have in my working configuration file:

<IfModule mod_ssl.c>   
  <VirtualHost _default_:443>
    ServerAdmin www@srv.fbh

    ServerName *.srv.fbh
    VirtualDocumentRoot /www/%0/ 

    SSLEngine on
    SSLCertificateFile    /etc/ssl/test/server.crt
    SSLCertificateKeyFile /etc/ssl/test/server.key   
  </VirtualHost>
</IfModule>

Also, you have a ServerAlias for www.domain.com - this is not necessary, as the wildcard *.domain.com will catch this.

  • Hmmm, this didn't seem to fix the problem. – mdgreenwald Feb 13 '11 at 18:51
  • Part of problem is in the VirtualDocumentRoot line. %0 expands to the incoming domain name, which in your case means Apache would look for the site at /www/www.domain.com, which is not /www/domain.com. You could work around this by creating a symlink from one to the other, which is similar to what you did, or a better way would be to modify the VirtualDocumentroot to be VirtualDocumentRoot /www/%-2.0.%-1, which means to take the penultimate and ultimate parts of the incoming domainname, with a dot in between. Both domains would resolve to the path /www/domain.com. – Martijn Heemels Jul 28 '12 at 4:03
0

This:

<IfModule mod_ssl.c>
  <VirtualHost *:443>
    ServerAlias *
    UseCanonicalName Off
    VirtualDocumentRoot /var/www/%0

    SSLEngine on
    SSLCertificateFile      /path-to-keys/ca.crt
    SSLCertificateKeyFile   /path-to-keys/yours.key
    SSLCertificateChainFile /path-to-keys/bundle.crt

    RequestHeader set X_FORWARDED_PROTO 'https'
  </VirtualHost>
</IfModule>

Of course you need the proper files there, and remember to set yours.key to chmod 400. I did notice you got this part working already, just keeping the answer more complete. ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.