文强的博客

  • Python
  • Linux
  • 建站教程
  • 百度一下
登高望远
无愧于心,不困与情,不念过去,无畏将来
  1. 首页
  2. 技术文章
  3. 正文

📜 零成本开启HTTPS!Ubuntu 24.04 + Certbot 申请 Let's Encrypt 证书终极指南

2025年7月11日 123点热度 0人点赞 0条评论

🔥 为什么需要 Let's Encrypt 证书?

Let's Encrypt 是由ISRG推出的免费、自动化、开放的证书颁发机构(CA),旨在推动全网HTTPS化。Certbot是其官方推荐的工具,支持一键申请和自动续期🔒,90天有效期 + 自动续签的特性帮你彻底告别证书过期的噩梦!

🛠️ 环境准备(Ubuntu 24.04)

  1. 更新系统包:sudo apt update && sudo apt upgrade -y
  2. 安装必要依赖:sudo apt install snapd -y(Ubuntu 24.04强制使用Snap安装)
  3. 验证80/443端口开放:确保防火墙放行sudo ufw allow 'Nginx Full'

🚀 三步安装 Certbot

❏ 复制
# 1. 安装Certbot核心组件
sudo snap install --classic certbot

# 2. 创建软链接到系统路径
sudo ln -s /snap/bin/certbot /usr/bin/certbot

💡 通过certbot --version验证安装,成功会显示类似certbot 2.10.0的版本号

🌐 申请证书(Nginx示例)

▸ 自动模式(推荐给小白)

❏ 复制
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

✨ 系统会自动修改Nginx配置,开启HTTPS重定向,全程交互式提示输入邮箱和协议条款。

▸ 手动模式(适合自定义配置)

❏ 复制
sudo certbot certonly --webroot \
-w /var/www/html \  # 站点根目录
-d yourdomain.com \
-d api.yourdomain.com

⚠️ 使用前需在Nginx配置中添加验证路由:
location /.well-known/acme-challenge/ { root /var/www/html; }

⏰ 搞定自动续期!

Certbot已自动创建续期定时任务,检查方法:

❏ 复制
sudo systemctl list-timers | grep certbot
# 应显示:snap.certbot.renew.timer → 每天自动触发

📌 手动测试续期:sudo certbot renew --dry-run

🚨 常见踩坑解决方案

  • 端口占用错误:停用占用80端口的服务(如Apache)sudo systemctl stop apache2
  • 申请通配符证书:需DNS验证sudo certbot certonly --manual --preferred-challenges=dns -d *.yourdomain.com
  • 证书存储位置:所有证书保存在/etc/letsencrypt/live/yourdomain.com/

💎 终极提示:用curl https://yourdomain.com测试HTTPS状态,浏览器锁图标亮起就是胜利!

🎯 写在最后

Let's Encrypt + Ubuntu 24.04的组合让HTTPS部署成本归零🆓。现在就去为你的网站穿上加密盔甲吧!遇到问题?欢迎在评论区开火提问~ 👇

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: certbot https let's encrpyt nginx ssl证书 ubuntu
最后更新:2025年7月11日

文强

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

归档

  • 2025 年 7 月

分类

  • Java
  • Linux
  • 建站教程
  • 技术文章

COPYRIGHT © 2025 文强的博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

赣ICP备2021010953号-3