Let's Encrypt SSL 证书申请完整指南

什么是 Let's Encrypt?

Let's Encrypt 是一个免费、自动化、开放的证书颁发机构(CA),提供免费
SSL/TLS 证书,可用于网站 HTTPS 加密。

其特点包括: - 免费 - 自动化申请与续期 - 全球信任 -
开源公益


一、环境准备

在 Linux(Ubuntu/Debian/CentOS)服务器上,你需要: - 已解析到服务器的
域名 - 已安装 Nginx 或 Apache - 服务器能访问互联网

查看域名 DNS 是否正确解析:

dig yourdomain.com

二、安装 Certbot(推荐)

Certbot 是 Let's Encrypt 官方提供的自动化申请工具。

Ubuntu/Debian:

sudo apt update
sudo apt install certbot python3-certbot-nginx

CentOS / Rocky / AlmaLinux:

sudo dnf install certbot python3-certbot-nginx

三、使用 Certbot 自动申请证书(Nginx)

执行以下命令:

sudo certbot --nginx

Certbot 会自动: 1. 检测你的域名 2. 自动配置 Nginx 3. 自动申请证书 4.
自动开启 HTTPS

安装完成后,你会看到类似提示:

Congratulations! Your certificate and chain have been saved...

四、手动指定域名申请证书

如果需要手动指定:

sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

五、证书自动续期

Let's Encrypt 证书有效期为 90 天,Certbot 会自动续期。

查看续期任务:

systemctl status certbot.timer

手动测试:

sudo certbot renew --dry-run

六、常见问题

1. 域名未解析或解析未生效

解决办法:确认 DNS 记录指向服务器公网 IP。

2. 防火墙未开放 80/443

执行:

sudo ufw allow 80
sudo ufw allow 443

3. Nginx server_name 配置不正确

正确示例:

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
}

七、Nginx 证书路径(默认)

成功申请后,证书文件位于:

/etc/letsencrypt/live/yourdomain.com/fullchain.pem
/etc/letsencrypt/live/yourdomain.com/privkey.pem

八、总结

使用 Let's Encrypt 可以: - 快速实现 HTTPS - 免费获得可信证书 -
自动更新,无需人工干预

Certbot 是最推荐的申请方式,特别适合 Nginx/Apache 服务器。

posted @ 2025-12-09 10:26  nemosc  阅读(337)  评论(0)    收藏  举报