在Ubuntu上使用Certbot申请Let’s Encrypt SSL证书
1 引言
要使用HTTPS就必须得有SSL证书。理论上,证书是可以通过像OpenSSL这样得工具生成的。不过这种证书只能自己测试用,浏览器上面是不认的,会提示用户不安全。也就是说,浏览器只接受一些特定的证书颁发机构(CA)发布的证书。正规的商业应用上,这些证书是需要像这些机构购买的。不过好在还是有像Let’s Encrypt这样开放的证书颁发机构,可以免费向其申请SSL证书,不过缺点是证书有效期只能有90天。
2 详叙
2.1 安装
Certbot是一个免费、自动化、开源的工具,可以用于向Let’s Encrypt申请SSL证书。在Ubuntu下使用如下指令安装Certbot:
sudo apt install certbot
如果提示不识别Certbot,那么可能需要添加Certbot的官方PPA源:
sudo apt install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt update
另外,使用Snap也可以安装Certbot:
sudo snap install --classic certbot
2.2 域名
一般来说,我们申请到的域名都是主域名,例如笔者申请的charlee44.com。除此之外,泛域名:*.charlee44.com也很常用。比如使用charlee44.com建了一个网站,随着功能的扩充,你就有了建立子网站sub.charlee44.com的需求了。因此最好是让主域名和泛域名合用同一个证书,以避免重复申请。
2.3 步骤
在终端中执行如下指令:
certbot certonly -d charlee44.com -d *.charlee44.com --manual --preferred-challenges dns
这个指令的意思是给charlee44.com和*.charlee44.com一起申请一个证书。此时会有如下提示:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for charlee44.com and *.charlee44.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:
_acme-challenge.charlee44.com.
with the following value:
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
这段命令提示的意思是将xxxxxxxxxxxxxxxxxxxxxxxxxxxx这段字符串设置成域名_acme-challenge.charlee44.com的TXT类型解析结果。这个步骤需要在域名服务商的后台中进行配置。
点击回车:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:
_acme-challenge.charlee44.com.
with the following value:
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
(This must be set up in addition to the previous challenges; do not remove,
replace, or undo the previous challenge tasks yet. Note that you might be
asked to create multiple distinct TXT records with the same name. This is
permitted by DNS standards.)
Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.charlee44.com.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
因为我们是给两个域名生成证书,因此需要将之前的步骤再来一遍。注意,主域名和泛域名是将不同的xxxxxxxxxxxxxxxxxxxxxxxxxxxx字符串,设置成相同域名_acme-challenge.charlee44.com的TXT类型解析结果。在阿里云域名后台中,就是给_acme-challenge.charlee44.com域名解析提供两个结果,如下所示:

点击回车:
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/charlee44.com-0001/fullchain.pem
Key is saved at: /etc/letsencrypt/live/charlee44.com-0001/privkey.pem
This certificate expires on 2025-09-29.
These files will be updated when the certificate renews.
NEXT STEPS:
- This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
* Donating to EFF: https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
可以看到生成了两个SSL证书文件:
- /etc/letsencrypt/live/charlee44.com-0001/fullchain.pem:服务器需要发送给客户端的完整证书链。
- /etc/letsencrypt/live/charlee44.com-0001/privkey.pem:证书私钥,与证书一起使用,以证明拥有该证书对应的公钥。
一般的HTTPS使用这两个证书文件即可。
3 参考
在Ubuntu上使用Certbot申请Let’s Encrypt SSL证书的更多相关文章
- ZeroSSL,支持多域名的在线 Let's Encrypt SSL 证书申请工具
前言: 微信需要ssl证书,很多网站都有免费一年的证书:免费一年的证书叫做单域名证书,iis没办法配置多个子站点443端口:我有很多客户需要用我的的域名,同一个域名配置多个ssl,或者支持多个子域名: ...
- Let's Encrypt SSL证书申请
当前环境: 阿里云CoreOS 所绑定的域名,解析管理也在阿里这儿,在该文档中使用 example.com 作为示例. Docker 镜像 acme.sh:2.8.8 nginx 申请证书并使用 使用 ...
- Nginx 通过 certbot 为网站自动配置 SSL 证书并续期
一.背景知识 1.1.http 和 https 是什么? 简单来说,http 是一个传输网页内容的协议,比如你看到的 http 开头的网站 http://www.163.com ,其网页上的文字.图片 ...
- Nginx 配置 HTTPS 完整过程(阿里云申请免费版一年ssl证书)
1. nginx 的 ssl 模块安装 查看 nginx 是否安装 http_ssl_module 模块. $ /usr/local/nginx/sbin/nginx -V 如果出现 configur ...
- 如何申请阿里云免费SSL证书(可用于https网站)并下载下来
前提条件:你要有阿里云的账号,并且要有一个域名. 注意:阿里云系统也在不断更新,界面以后可能会有稍许变化,但是原理是相通的. 具体步骤: 1.登录到阿里云后台,并选择 “SSL证书(应用安全)” 菜单 ...
- 免费SSL证书申请及部署实践
网络上关于如何签发免费SSL证书的博文一大片,但是真正操作起来的能让新手不迷惑的却很少,很多操作步骤受限于国内无法访问外网的阻碍,导致无法真正实施成功. 实际上,关于申请免费SSL证书主要涉及两大部分 ...
- 入门系列之在Ubuntu上安装Drone持续集成环境
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由小铁匠米兰的v 发表于云+社区专栏 介绍 Drone是一个流行的持续集成和交付平台.它集成了许多流行的版本控制存储库服务,如GitHu ...
- 亚马逊EC2服务器申请+NODE服务器部署+阿里云域名申请+SSL证书使用
最近,由于项目需要,自己申请了一台亚马逊用于部署网站测试,在使用期间,发现网上没有一篇非常完整的文章讲解从服务器申请到域名解析,SSL证书申请的整个流程.所以自己总结一下,以供大家学习! 一.亚马逊E ...
- Let's Encrypt 免费通配符 SSL 证书申请教程——但是也需要email,域名所有权等,如果是黑产用的话会这样用吗?会不会暴露自己身份???
Let's Encrypt 免费通配符 SSL 证书申请教程 from:https://blog.csdn.net/English0523/article/details/79608464 2018 ...
- 申请 Let’s Encrypt 泛域名证书 及 Nginx/Apache 证书配置
什么是 Let’s Encrypt? 部署 HTTPS 网站的时候需要证书,证书由 CA (Certificate Authority )机构签发,大部分传统 CA 机构签发证书是需要收费的,这不利于 ...
随机推荐
- Code First 初始化数据时发生异常
问题重现 用Entity Framework的Code First默认生成的数据库文件被我直接删除了, 然后不管怎么重新编译等等, 运行后总是会报错如下: 解决方案同下 Cannot attach t ...
- 写给自己的话,学院派 C 转 实用派Java
本人计算机专业出身,学校学习过C / VC++. 写过很一般的代码, 刷过北大百炼 ACM 的部分试题.学过数据结(还可以),数据库(学的一般会用sql).用 c指针链表构建过二叉树实现过哈夫曼编码加 ...
- Model接口
/** * Model接口 * 作用:将值存放到request对象 * * * @return */ @RequestMapping(value = "/testModle") p ...
- eolinker脚本代码[Javascript]:脚本(函数)之间传参案例
场景描述: 有等级卡A.B,依次通过查询A.B,检查A.B下是否会会员,如果有,调整会员身份,没有着执行下一个循环 全部脚本:脚本中红色标注的user即脚本之间的传参 //以下代码为示例代码(支持原生 ...
- 快速理解 MCP 与 A2A 协议的关系,它们如何协作构建复杂AI系统
近期关于MCP协议的讨论非常热门,主要因为通过MCP协议通过标准化接口为 AI 应用与外部数据源建立统一交互通道,这使得大模型可以与外部数据源或工具进行交互,从而实现各种专业场景下的智能应用.关于如何 ...
- CF1424G题解
思路 这个题意思很显然,是求 nnn 个区间重叠最多的地方和值. 那么我们能想到用差分数组,在扫一遍的过程中维护最大值和 pospospos. 但是需要注意的是,区间最大会到 10910^9109,直 ...
- DOC,PDF,PPT文件转换为HTML代码记录
pom文件引入 <repositories> <repository> <id>com.e-iceblue</id> <url>http:/ ...
- maven-helper解决依赖冲突
idea中可以使用maven-helper解决依赖冲突
- .NET周刊【5月第1期 2025-05-04】
dotnet 9 通过 AppHostRelativeDotNet 指定自定义的运行时路径 https://www.cnblogs.com/lindexi/p/18847625 这篇文章讨论了在 .N ...
- ModelForm验证笔记
Form验证 UserInfoForm --> Form -->BaseForm(is_valid...) UserInfoModelForm -->ModelForm ...