I have installed SSL on a subdomain of my site. Everything works perfectly, except this strange behavior.
If I point my browser at the following locations, these document roots are served:
http://domain.com -> /var/www [GOOD]
https://sub.domain.com -> /media/sub [GOOD]
https://domain.com -> /media/sub [BAD]
The last URL on that list should serve /var/www
, not /media/sub
. In other words, I would like to safely redirect users from https://domain.com
to http://domain.com
.
Here are my VirtualHosts.
domain.com
<VirtualHost *:80>
ServerName domain.com
DocumentRoot /var/www
</VirtualHost>
sub.domain.com
<VirtualHost *:443>
ServerName sub.domain.com:443
DocumentRoot /media/sub
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
</VirtualHost>
What I've Tried
It was suggested to me that https://domain.com
is serving the wrong VirtualHost because there is no *:443
VirtualHost with a ServerName
of domain.com
.
To fix this, I have tried doing this:
domain.com
<VirtualHost *:80>
ServerName domain.com
DocumentRoot /var/www
</VirtualHost>
<VirtualHost *:443>
ServerName domain.com
Redirect / http://domain.com/
</VirtualHost>
I feel like this should work. (It should redirect https
requests to http
, thus serving the correct document root.)
However, when I do this, Apache2 will not even start. It gives me this error:
[error] Server should be SSL-aware but has no certificate configured [Hint: SSLCertificateFile] ((null):0)
Thanks a lot in advance for any guidance.