SSL automático con Certbot y systemd timers
Renovación sin cron, recarga de Nginx con hooks y alertas cuando algo falla.
Contenido
Los certificados de Let's Encrypt duran 90 días. Certbot ya trae un timer de systemd, pero conviene revisarlo, agregar el hook de recarga y enterarse cuando falle.
Emitir el certificado
terminalbash
$ sudo apt install certbot python3-certbot-nginx
$ sudo certbot --nginx -d klog.dev -d www.klog.devEl timer de systemd
terminalbash
$ systemctl list-timers certbot.timer
NEXT LEFT UNIT
Sat 2026-10-21 21:12:00 CST 12h left certbot.timerSi tu distribución no lo trae, créalo:
configuraciónini
# /etc/systemd/system/certbot.timer
[Unit]
Description=Renovación de certificados dos veces al día
[Timer]
OnCalendar=*-*-* 00,12:00:00
RandomizedDelaySec=1h
Persistent=true
[Install]
WantedBy=timers.targetRecargar Nginx tras renovar
terminalbash
#!/bin/sh
# /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh
nginx -t && systemctl reload nginxNota: los hooks en deploy/ solo se ejecutan cuando un certificado realmente se renovó.
Alertas cuando falla
configuraciónini
# systemctl edit certbot.service
[Unit]
OnFailure=notify-failure@%n.serviceVerificar
terminalbash
$ sudo certbot renew --dry-run
# all simulated renewals succeeded