ubuntu部署ssl证书

证书安装

在进行证书安装前,需要将域名的 DNS 指定到你的 ubuntu 服务器节点上,ubuntu 安装 Let's Encrypt 证书步骤如下

安装 certbot 工具

shell 复制代码
apt update
apt install certbot python3-certbot-nginx

运行 certbot 命令进行证书安装

对于 nginx

shell 复制代码
certbot --nginx -d mydomain.com -d www.mydomain.com

对于 apache

shell 复制代码
certbot --apache -d mydomain.com -d www.mydomain.com

如果不填写邮箱的话,可以指定 certbot 参数 --register-unsafely-without-email,生成证书的输出如下

shell 复制代码
root@ubuntu:~# certbot --nginx -d mydomain.com -d www.mydomain.com --register-unsafely-without-email 
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.5-February-24-2025.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: 
(Y)es/(N)o: y
Account registered.
Requesting a certificate for mydomain.com and www.mydomain.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/mydomain.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/mydomain.com/privkey.pem
This certificate expires on 2025-06-13.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for mydomain.com to /etc/nginx/nginx.conf
Successfully deployed certificate for www.mydomain.com to /etc/nginx/nginx.conf
Congratulations! You have successfully enabled HTTPS on https://mydomain.com and https://www.mydomain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

自动续订证书

Let's Encrypt 证书的有效期为 90 天,需要定期续订避免过期,Certbot 会自动设置一个系统定时器,以自动续订证书

可以使用以下命令来测试证书续订

shell 复制代码
certbot renew --dry-run

输出信息如下

shell 复制代码
root@ubuntu:~# certbot renew --dry-run 
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/mydomain.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for mydomain.com and www.mydomain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded: 
  /etc/letsencrypt/live/mydomain.com/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
相关推荐
RollingPin41 分钟前
iOS八股文之 网络
网络·网络协议·ios·https·udp·tcp·ios面试
添砖java‘’5 小时前
vim高效编辑:从入门到精通
linux·编辑器·操作系统·vim
tryCbest6 小时前
CentOS部署Docker容器
linux·docker·centos
qyhua7 小时前
【Linux运维实战】彻底修复 CVE-2011-5094 漏洞
linux·运维·安全
坠金7 小时前
linux/centos迁移conda文件夹
linux·centos·conda
纳于大麓8 小时前
Kotlin基础语法
linux·windows·kotlin
九皇叔叔8 小时前
Linux Shell 正则表达式中的 POSIX 字符集:用法与实战
linux·运维·正则表达式
東雪蓮☆9 小时前
K8s 平滑升级
linux·运维·云原生·kubernetes
---学无止境---10 小时前
Linux中进程创建和缓存对象初始化fork_init、proc_caches_init和buffer_init
linux
站长朋友10 小时前
【邀请函】锐成信息 × Sectigo | CLM - SSL 证书自动化运维解决方案发布会
运维·自动化·ssl·clm·sectigo·47天ssl证书