Assuming you have apache2 installed run the following commands:

a2enmod ssl
a2enmod rewrite
a2ensite default-ssl

edit the file /etc/apache2/sites-available/default and add the following lines exactly under the <VirtualHost *:80> line:

  • <VirtualHost *:80>
    • RewriteEngine On
    • RewriteCond %{HTTPS} off
    • RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

/etc/init.d/apache2 restart