Engadir cifrado https con certbot nun servidor Apache

1. Instalar certbot e python-cerbot-apache
apt-get install -t certbot apt-get install -t python-certbot-apache
2. Activamos módolos ssl
sudo a2enmod ssl
pero se ao reiniciar o servizo de apache, é posible que falle.
systemctl restart apache2
Solución
Non conseguía que arrancara o Apache, daba erro. O problema era debido a que outro programa está empregando o porto 443. Coa seguinte instrucción pódese averiguar de cal se trata, moi probablemente sexa o sshd. Debemos de paralo, e seguidamente iniciamos de novo o servizo de Apache. No meu caso tiven que reinstalar posteriormente o ssh-server.
netstat -tlpn | grep 443 service sshd stop systemctl restart apache2
3. Creamos os ficheiros coas chaves públicas e privadas. Unha vez creadoos, aparecerán na seguinte ruta: /etc/letsencrypt/live/
certbot certonly --webroot -w /var/www/html/tic -d blog.atio.es
Se ao final aparece a seguinte mensaxe, fixémolo ben
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/www.atio.es/fullchain.pem. Your cert will
expire on 2018-05-16. To obtain a new or tweaked version of this
certificate in the future, simply run certbot again. To
non-interactively renew *all* of your certificates, run "certbot
renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
4. Debemos de configurar o virtual host /etc/apache2/site-avaliable
#Páxina web do servidor do centro <VirtualHost 128.199.58.55:80> ServerAdmin martindetecnoloxia@gmail.com ServerName http://www.atio.es ServerAlias blog.atio.es # Indexes + Directory Root. DirectoryIndex index.php DocumentRoot /var/www/html/drupal Options FollowSymLinks <Directory "/var/www/html/drupal"> AllowOverride All </Directory> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} </VirtualHost> <VirtualHost 128.199.58.55:443> ServerAdmin martindetecnoloxia@gmail.com ServerName http://www.atio.es ServerAlias blog.atio.es # Indexes + Directory Root. DirectoryIndex index.php DocumentRoot /var/www/html/drupal Options FollowSymLinks <Directory "/var/www/html/drupal"> AllowOverride All </Directory> SSLEngine on SSLCertificateFile /etc/letsencrypt/live/blog.atio.es/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/blog.atio.es/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/blog.atio.es/chain.pem </VirtualHost>
Co seguinte código engadido no código que acabamos de visualizar forzamos a visualización da páxina en https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Borramos /etc/apache2/site-enabled/atio.es.conf
Volemos a /etc/apache2/site-avaliable
a2ensite atio.es.conf systemctl reload apache2
5. Abrimos o cortafuegos. No meu caso engadín as seguintes instrucións
sudo ufw allow 'WWW Full'
sudo ufw allow 'SSH'
sudo iptables -I INPUT -p tcp --dport 443 -j ACCEPT
6. Engadimos unha tarefa cron para que nos renove os certificados, pois caducan aos 90 días
Crontab -e 30 1 * * 1 /usr/bin/certbot renew >> /var/log/le-renew.log