1️⃣ Nếu dùng Certbot (phổ biến nhất)

Kiểm tra certbot đã có chưa

certbot --version

2️⃣ Test thử renew thủ công

sudo certbot renew --dry-run

Nếu báo Congratulations là OK.


3️⃣ Tự động renew bằng systemd (Ubuntu 18+)

Let’s Encrypt cài qua apt thường đã có sẵn timer.

Kiểm tra:

systemctl list-timers | grep certbot

Nếu thấy:

certbot.timer

=> Đã tự động chạy 2 lần/ngày.

Kiểm tra trạng thái:

systemctl status certbot.timer

4️⃣ Nếu chưa có timer → dùng cron

Mở cron:

sudo crontab -e

Thêm dòng:

0 3 * * * certbot renew --quiet && systemctl reload nginx

Giải thích:

PhầnÝ nghĩa
0 3 * * *3h sáng mỗi ngày
certbot renewkiểm tra và gia hạn
--quietkhông log rác
reload nginxload lại SSL mới

5️⃣ Nếu dùng Nginx cần reload sau khi renew

Có thể cấu hình hook luôn:

sudo certbot renew --deploy-hook "systemctl reload nginx"

Hoặc tạo file:

sudo nano /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh

Nội dung:

#!/bin/bash
systemctl reload nginx

Rồi:

chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh

6️⃣ Kiểm tra SSL hết hạn khi nào

openssl x509 -enddate -noout -in /etc/letsencrypt/live/domain.com/fullchain.pem

Hoặc:

certbot certificates

⚠ Lưu ý quan trọng

Let’s Encrypt:

  • Chỉ gia hạn khi còn dưới 30 ngày
  • SSL có hạn 90 ngày
  • Nếu dùng Cloudflare Full (Strict) vẫn renew bình thường

🎯 Nếu bạn dùng Cloudflare Tunnel

Trường hợp:

  • Server local
  • Cloudflare proxy
  • SSL edge tại Cloudflare

→ Có thể không cần Let’s Encrypt ở server.