因为 Certbot 官方主要支持 Linux 环境(例如 Ubuntu、CentOS、Debian),但在 Windows 上你同样可以使用它来申请和续期 Let's Encrypt 免费 HTTPS 证书。下面我详细讲讲在 Windows 上使用 Certbot 的几种方式👇
🧩 一、Certbot 简介
Certbot 是由 EFF(电子前哨基金会) 开发的免费自动化工具,用于从 Let’s Encrypt 申请 SSL/TLS 证书并自动续期。
它可以:
- 自动验证域名所有权;
- 申请、安装证书;
- 自动续期(90 天一次)。
🪟 二、在 Windows 上使用 Certbot 的几种方式
✅ 方式 1:使用 Windows Subsystem for Linux(WSL)
这是最推荐的方式(简单、稳定)。
步骤:
-
安装 WSL 与 Ubuntu
在 Windows PowerShell(管理员模式)执行:wsl --install -d Ubuntu安装完成后重启电脑。
-
进入 WSL(Ubuntu)
打开 PowerShell 或 Windows Terminal:wsl -
安装 Certbot
sudo apt update sudo apt install certbot -y -
申请证书
比如你要给example.com配置 HTTPS:sudo certbot certonly --standalone -d example.com -d www.example.comCertbot 会自动启动临时 HTTP 服务验证域名。
-
找到生成的证书
通常在:/etc/letsencrypt/live/example.com/包含:
fullchain.pem:证书链(用于 Nginx)privkey.pem:私钥文件
-
复制证书到 Windows 系统
在 PowerShell 中运行:wsl cp /etc/letsencrypt/live/example.com/fullchain.pem C:\nginx\certs\ wsl cp /etc/letsencrypt/live/example.com/privkey.pem C:\nginx\certs\ -
Nginx 配置(Windows 版本)
server { listen 443 ssl; server_name example.com; ssl_certificate C:/nginx/certs/fullchain.pem; ssl_certificate_key C:/nginx/certs/privkey.pem; location / { root html; index index.html; } }
✅ 方式 2:使用 Certbot Docker 镜像
如果你不想安装 WSL,可以直接使用 Docker(同样适合 Windows)。
步骤:
-
执行命令申请证书:
docker run -it --rm --name certbot \ -v C:\certbot\etc\letsencrypt:/etc/letsencrypt \ -v C:\certbot\var\lib\letsencrypt:/var/lib/letsencrypt \ -p 80:80 \ certbot/certbot certonly --standalone -d example.com -
成功后证书会保存到
C:\certbot\etc\letsencrypt\live\example.com
✅ 方式 3:使用 acme.sh(推荐给纯 Windows 环境)
如果你不想用 WSL 或 Docker,Certbot 原生在 Windows 上比较麻烦,可以考虑另一个轻量级工具:
🔹 acme.sh
这是一个纯 Shell 实现的 Let’s Encrypt 客户端,支持 Windows(Git Bash / Cygwin)。
示例:
-
安装 Git Bash
-
执行:
curl https://get.acme.sh | sh -
申请证书:
~/.acme.sh/acme.sh --issue -d example.com --standalone -
安装证书到 nginx 目录:
~/.acme.sh/acme.sh --install-cert -d example.com \ --key-file C:\nginx\certs\privkey.pem \ --fullchain-file C:\nginx\certs\fullchain.pem
🔁 三、证书续期
自动续期(WSL / Docker)
Certbot 的证书有效期是 90 天。
自动续期命令:
sudo certbot renew
可以加到定时任务(crontab)中。
🧠 四、补充建议
| 需求 | 推荐方式 |
|---|---|
| 有 Nginx、Apache 服务器 | Certbot |
| 纯 Windows 无 Linux 环境 | acme.sh |
| 有 Docker 环境 | Certbot + Docker |
| 想长期稳定自动续期 | Linux + Certbot + cron |