使用Certbot申请免费 HTTPS 证书及自动续期

随着各个脚本的安全性越来越差,越来越多的我倾向于自行编译lnmp环境。但自行编译环境申请SSL证书一直是个问题,今天给大家介绍一个好用的工具:CertBot来实现证书的申请及自动续期。以下所有操作均运行在 Debian服务器。本机环境是Debian12首先,我们要安装 Snapdsu root ap

随着各个脚本的安全性越来越差,越来越多的我倾向于自行编译lnmp环境。但自行编译环境申请SSL证书一直是个问题,今天给大家介绍一个好用的工具:CertBot来实现证书的申请及自动续期。

以下所有操作均运行在 Debian服务器。本机环境是Debian12

首先,我们要安装 Snapd

su root
apt update
apt install snapd

安装Snapd-core

sudo snap install core

安装CertBot

sudo snap install --classic certbot

链接CertBot到/usr/bin目录

sudo ln -s /snap/bin/certbot /usr/bin/certbot

给nginx环境安装证书,指定nginx的conf目录和nginx的执行目录,配置证书是自动完成的。

certbot --nginx --nginx-server-root=/usr/local/nginx/conf --nginx-ctl=/usr/local/nginx/sbin/nginx

以下是自动申请证书的输出结果,中间需要输入邮箱及一些确认。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): admin@1stcache.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y    

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
Account registered.

Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: oss.1stcache.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Requesting a certificate for oss.1stcache.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/oss.1stcache.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/oss.1stcache.com/privkey.pem
This certificate expires on 2024-02-14.
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 oss.1stcache.com to /usr/local/nginx/conf/nginx.conf
Congratulations! You have successfully enabled HTTPS on https://oss.1stcache.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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
root@sweaty-balance:/usr/local/nginx# 

现在再使用https来访问我们的网站,发现已经大功告成了。

别急,我们需要全自动续期呢。

sudo certbot renew --dry-run

这个命令会帮我们自动续期,现在才算ok了。

/etc/crontab/
/etc/cron.*/*
systemctl list-timers

查看以上目录确认续期ok。

整个流程其实非常简单。脱离面板其实也没有那么难。

购买必读
本站模板没有任何后门,也不会和我们服务器有任何通信,请您放心使用。
本源码一次性买断,没有二次费用,并享受免费更新。
在使用本站模板时,请不要使用我们的产品从事违反中华人民共和国法律、违反公序良俗的活动,否则我们有权拒绝服务,并配合有关单位予以处置。如果您不符合条件,请勿购买。
售后是指通过QQ与客服联系处理问题,售后过期不影响您对主题的使用和更新。免费三个月售后服务。售后服务时间为工作日早9点到晚5点。如果不在线可以QQ留言,我们会尽快给您答复。
售后服务包括程序的使用、BUG的处理、意见建议等。不包括技术服务、网站优化、二次开发、环境配置、服务器运维等。
代码类商品属于数字化商品,具有可复制性,不支持退款,详见《网络交易管理办法》第二章 第16条 第三类。
请仔细阅读我们的用户协议:用户协议

给TA打赏
共{{data.count}}人
人已打赏
管理面板

宝塔强化WAF防护-开启5秒盾-轻松防CC攻击!

2023-10-26 15:08:57

主机运维管理面板

2023宝塔 Linux 面板开心版

2023-12-6 14:21:59

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧

线

专属客服

(工作日 10:00 - 22:30 为您服务)

2026-09-21 00:15:56

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

猜你想问:

  • 购买的模板免费包安装吗?

  • 这个演示地址有吗?

  • 购买vip会员可以下载哪些模板?

您的工单我们已经收到,我们将会尽快跟您联系!
取消

您想了解哪方面的问题?

选择聊天工具: