I’m using Ubunutu and didn’t manipulate the file 000-default.conf
because I prefer it stays like it is.
I did a2dissite 000-default.conf
and then added two files below /etc/apache2/sites-available
:
redirect-to-ssl.conf
redirects all HTTP traffic (port 80) to HTTPS (port 443):
<VirtualHost *:80>
ServerName my.server.name
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</VirtualHost>
And my.server.name-ssl.conf
to handle that SSL traffic:
<VirtualHost *:443>
ServerName my.server.name
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/my.server.name/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/my.server.name/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
Then I did
a2enmod ssl
a2ensite redirect-to-ssl.conf
a2ensite my.server.name-ssl.conf
systemctl restart apache2.service
Of course you have to adapt the SSL file paths to yours.
You may also want to try apachectl configtest
to check the configuration.
Update: In a previous version I wrote systemctl status apache2
. Of course it is restart
.