开启Let’s Encrypt免费HTTPS证书

本教程记录了如何在阿里云服务器上开启Let’s Encrypt 免费 HTTPS 证书的完整过程

📌 前置条件
  1. 已备案的域名
  2. 域名已解析到服务器公网 IP
  3. Nginx 已经安装

[!WARNING]

如果是国外的服务器域名可不用备案

🛠️ 步骤

1、安装 Certbot

在服务器执行:

1
2
sudo apt update
sudo apt install certbot python3-certbot-nginx -y

2、申请证书

执行:

要有root权限

1
certbot --nginx -d 域名 -d www.域名

交互过程:

  1. 输入邮箱:
1
2
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): youremail@example.com(你的邮箱)
  1. 接受服务条款:
1
2
Do you agree?
(Y)es/(N)o: Y
  1. 是否分享邮箱给 EFF:
1
2
Would you be willing to share your email with the Electronic Frontier Foundation?
(Y)es/(N)o: N

成功后返回:

1
2
3
4
5
6
7
8
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/huishao.fun/fullchain.pem
Key is saved at: /etc/letsencrypt/live/huishao.fun/privkey.pem
This certificate expires on 2025-12-29.
Deploying certificate
Successfully deployed certificate for huishao.fun to /etc/nginx/conf.d/hexo.conf
Successfully deployed certificate for www.huishao.fun to /etc/nginx/conf.d/hexo.conf
Congratulations! You have successfully enabled HTTPS on https://huishao.fun and https://www.huishao.fun

[!IMPORTANT]

如果第一次申请证书失败可以再重新执行

3、检查是否 Nginx 自动跳转 HTTPS(可选)

在 /etc/nginx/conf.d/nginx.conf 中增加:

根据自己配置文件为主,一般certbot都会默认加上去的

1
2
3
4
5
server {
listen 80;
server_name huishao.fun www.huishao.fun;
return 301 https://$host$request_uri;
}

4、测试访问


5、测试证书续签

执行:

1
sudo certbot renew --dry-run

成功返回:

1
Congratulations, all renewals succeeded

开启Let’s Encrypt免费HTTPS证书
http://huishao.net/2025/09/25/申请HTTPS证书/
作者
huishao
发布于
2025年9月25日
许可协议