I found many misleading guides on how to install SSL certificate so that both http and https can work for the same site. Below are the step by step instructions
- Enable mod_ssl,
sudo a2enmod ssl
- Put your certificate in
/etc/ssl/certs/example.com.crt
. Other directory may work, but I prefer this. - Put your key in
/etc/ssl/private/example.com.key
. Other directory may work, but I prefer this. - Add a new virtual host for https, e.g.
<VirtualHost *:443> DocumentRoot /path/to/project ServerName example.com DirectoryIndex index.html <Directory /path/to/directory> DirectoryIndex index.html Options FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> SSLEngine on SSLCertificateFile /etc/ssl/certs/example.com.crt SSLCertificateKeyFile /etc/ssl/private/example.com.key </VirtualHost>
- Restart Apache
sudo apache2ctl restart
Both http://example.com and https://example.com should work now.