原创:博客主机_自动申请续期免费证书

一不留神,之前的域名证书过期了。由于是Let’s Encrypt免费证书,需要3个月手工续期一次,一年就得4次,还是有点麻烦,搞成自动化多好。
以下操作均在服务器上执行(ubuntu16,腾讯云)

下载脚本certbot-auto

1
2
3
cd opt/
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto

执行certbot-auto可能报错:

1
An unexpected error occurred: UnicodeEncodeError: 'ascii' codec can't encode

说明脚本尝试修改nginx配置文件,结果文件中包含中文字符。这个本人更倾向于自主控制,不依赖脚本,脚本复仅仅负责生成证书或renew证书即可,证书的复制和配置还是人工脚本完成更佳。一方面可控性更强,另一方面遇到错误也知道怎么回事!

生成秘钥

命令

1
./certbot-auto certonly  -d *.example.cn --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
  1. certonly 安装模式
  2. -d 申请证书的域名,如果是通配符域名输入 *.example.cn
  3. –manual 手动安装插件
  4. –preferred-challenges dns 使用 DNS 方式校验域名所有权
  5. –server,Let’s Encrypt ACME v2 版本使用的服务器不同于 v1 版本,需要显示指定

响应

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Requesting to rerun ./certbot-auto with root privileges...
./certbot-auto has insecure permissions!
To learn how to fix them, visit https://community.letsencrypt.org/t/certbot-auto-deployment-best-practices/91979/
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for example.cn- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.example.cn with the following value:v8somjB6jyjkZ9-fi_5l705CA_ERu0hRJcGFbLpHNaQ#配置dns的txt解析Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
Waiting for verification...
Cleaning up challenges
Subscribe to the EFF mailing list (email: xxxxx(your email)@163.com).IMPORTANT NOTES:- Congratulations! Your certificate and chain have been saved at:/etc/letsencrypt/live/example.cn/fullchain.pemYour key file has been saved at:/etc/letsencrypt/live/example.cn/privkey.pemYour cert will expire on 2021-02-20. To obtain a new or tweakedversion of this certificate in the future, simply run certbot-autoagain. To non-interactively renew *all* of your certificates, run"certbot-auto renew"- If you like Certbot, please consider supporting our work by:Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donateDonating to EFF:                    https://eff.org/donate-le

以上命令需要注意2点
1,最好在部署服务的机器上执行
2,第二步需要修改dns记录,但是修改后未必实时生效,需要等到生效后再按“回车”,否则可能会生成失败

腾讯云的dns配置样例

验证dns解析生效的命令

1
2
# 域名为解析的二级域名nslookup -q=txt _acme-challenge.example.cn

返回如下信息说明配置生效了

生成的秘钥

1
2
3
4
5
6
7
(base) john@VM-0-3-ubuntu:~$ sudo ls -lh /etc/letsencrypt/live/example.cn
总用量 4.0K
lrwxrwxrwx 1 root root  33 Nov 22 16:25 cert.pem -> ../../archive/example.cn/cert1.pem
lrwxrwxrwx 1 root root  34 Nov 22 16:25 chain.pem -> ../../archive/example.cn/chain1.pem
lrwxrwxrwx 1 root root  38 Nov 22 16:25 fullchain.pem -> ../../archive/example.cn/fullchain1.pem
lrwxrwxrwx 1 root root  36 Nov 22 16:25 privkey.pem -> ../../archive/example.cn/privkey1.pem
-rw-r--r-- 1 root root 692 Nov 22 16:25 README

配置nginx

样例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
server {listen       443 ssl;server_name  localhost;location / {root   html;index  index.html index.htm;}ssl on;ssl_session_timeout 5m;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;ssl_prefer_server_ciphers on;ssl_certificate      /etc/letsencrypt/live/example.cn/fullchain.pem;# 若使用cert.pem虽证书有效,但浏览器依然会提示不安全ssl_certificate_key  /etc/letsencrypt/live/example.cn/privkey.pem;
}

修改后验证nginx:sudo nginx -t
验证ok后重启nginx:sudo service nginx restart
登录自己站点,点击地址栏的锁图标,可以发现证书已经生效

自动续期

免费的证书必须3个月续期1次,比较麻烦,可以添加定时任务脚本进行自动续期

1
2
touch sslrenew.sh
chmod +x sslrenew.sh

sslrenew.sh内容

1
<path to certbot>/certbot-auto renew

配置定时任务

1
2
3
编辑定时任务:crontab -e
0 0 1 * * /home/john/opt/sslrenew.sh #每月1日
查看定时任务:crontab -l

参考

certbot申请通配符域名证书:https://www.jianshu.com/p/7b65cc562bc3
[转]部署Let’s Encrypt免费SSL证书&&自动续期:https://www.cnblogs.com/lzpong/p/6433189.html
Let’sEncrypt 免费ssl证书申请并自动续期:https://blog.csdn.net/c__chao/article/details/88368048

博客主机_自动申请续期免费证书相关推荐

  1. 【好用的工具】搭建个人博客网站(域名备案 + https免费证书)

    前言 为什么选择搭建个人博客?一方面是各个平台经常下架原创文章,另一方面是为了熟悉整个建站流程. 通过搭建个人博客,我们可以自由的发表文章不用担心下载,而且可以锻炼个人的SEO优化能力,不管是运维还是 ...

  2. 从零搭建个人博客网站(域名备案 + https免费证书)

    为什么选择搭建个人博客?一方面是各个平台经常下架原创文章,另一个方面是为了熟悉整个建站流程. 通过搭建个人博客,我们可以自由的发表文章不用担心下架,而且可以锻炼个人的SEO优化能力,不管是运维还是运营 ...

  3. 从零到一快速搭建个人博客网站(域名备案 + https免费证书)

    作者:yangwqonly cnblogs.com/winkin/p/14135677.html 前言 为什么选择搭建个人博客?一方面是各个平台经常下架原创文章,另一个方面是为了熟悉整个建站流程. 通 ...

  4. 使用certbot自动申请续期SSL证书(Ubuntu)

    ##介绍 我们通过Certbot自动化完成SSL证书注册和配置文件修改步骤,从而在Web服务器上启用加密的HTTPS.目前,获取和安装证书的整个过程在Apache和Nginx上都是完全自动化的. 在本 ...

  5. 试客联盟试用自动申请工具v6.7官方版

    名称:试客联盟试用自动申请工具v6.7官方版 版本:6.7 大小:11.9MB 软件语言:中文简体 软件授权:免费版 应用平台:WinAll 软件介绍以及简介: 试客联盟试用自动申请工具是一款由一马软 ...

  6. 写个自己看的博客随笔_发布游戏或者应用

    游戏的发布平台 注意:时间>=2013年(低于者标注出),内容不定 写个自己看的博客随笔_发布游戏_之后再做补充 1,国外游戏平台 1,内容正文 1, http://ol.tgbus.com/y ...

  7. 网页附加题写出下图的html,附加题(写HTML文件):根据给定的博客名单,自动生成HTML网页...

    收集了学生CSDN博客地址很久了,但一直没来得及整理成贺利坚老师的完美班级网页名册.今天突然想,一共有6个班学生,如果手动写的话,太费事了.我们程序员,就是让费事不费脑的工作自动化,即使是第一次花很多 ...

  8. 个人博客管理系统_教程 | 一文搭建你的第一个免费专属博客

    点击蓝字关注我 本文将详细介绍利用Github+hexo搭建一个免费.简洁的个人博客,从获取域名到菜单栏.搜索框.评论分享这些必要功能的配置,给自己一个个性化的内容分享平台. -▼- 我建了一个QQ学 ...

  9. java基于ssm的个人博客系统_一个基于 Spring Boot 的开源免费博客系统

    概况 mblog 开源免费的博客系统, Java 语言开发, 支持 mysql/h2 数据库, 采用 spring-boot.jpa.shiro.bootstrap 等流行框架开发.支持多用户, 支持 ...

最新文章

  1. 重磅消息:Spring 6 和Spring Boot 3
  2. 用leangoo做阶段式游戏新产品研发
  3. 国家计划统筹布局哪些人工智能创新平台?
  4. 快速增强路由器安全的十个小技巧
  5. Entity Framework 基础
  6. 利用网站模板创建子网站
  7. 【话题揭秘】某大型国有银行的敏捷落地实践
  8. 克隆可序列化和不可序列化的Java对象
  9. 安卓java桌面图标程序_android如何定制默认桌面上应用程序和shortcut图标 | 学步园...
  10. shell脚本触发java程序支持传参补跑 +crontab定时器_02
  11. 聚合多个文件_python数据分析与挖掘(二十五)--- Pandas高级处理分组与聚合
  12. 智能会议系统(7)---实时音视频技术难点及解决方案
  13. 【Flink】flink ClickHouseSink--数据写入ClickHouse
  14. VC++调试方法和技巧
  15. maven(一)入门
  16. 企业级直播平台架构和设计
  17. 【SELinux】vendor_file_contexts没有被编译到vendor/etc/selinux/路径下
  18. c++ 三点求外接圆圆心 3维实现
  19. 计算机课程教学调查问卷,计算机基础课程调查问卷
  20. 常见概率抽样方法及其适用场景总结

热门文章

  1. 最小路径问题_Floyd
  2. MySql事务隔离级别概述
  3. 使用备份和还原以及SMB协议将SQL数据库从Windows迁移到Linux
  4. SQL Server中的报表–如何使用数据透视表和日期计算来获取有价值的报表
  5. SQL Server Always On可用性组中的数据同步
  6. swagger在springboot上的快速上手
  7. string的基本用法
  8. SQLSERVER2014集群实战——IP引发的坑
  9. Windows Server 2008 R2 主域控制器委派DNS到子域控控制器
  10. Cardboard开发教程:使用Unity制作Cardboard全景图片浏览器