ubuntu 18.04 Let is Encrypt单域名和泛域名SSL证书配置

2024-04-03 15:38

本文主要是介绍ubuntu 18.04 Let is Encrypt单域名和泛域名SSL证书配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、Let’s Encrypt简介
  • Let’s Encrypt 也是一个 CA 机构,但这个 CA 机构是免费的!!!也就是说签发证书不需要任何费用。
  • Let’s Encrypt 由于是非盈利性的组织,需要控制开支,他们搞了一个非常有创意的事情,设计了一个 ACME 协议,目前该协议的版本是 v1。
  • 那为什么要创建 ACME 协议呢,传统的 CA 机构是人工受理证书申请、证书更新、证书撤销,完全是手动处理的。而 ACME 协议规范化了证书申请、更新、撤销等流程,只要一个客户端实现了该协议的功能,通过客户端就可以向 Let’s Encrypt 申请证书,也就是说 Let’s Encrypt CA 完全是自动化操作的
  • 通配符证书就是证书中可以包含一个通配符,比如 .example.com、.example.cn,支持多个子域名使用同一个证书
二、certbot验证方式
  • cerbot验证方式有下面几种:apache,nginx,webroot,standalone,dns plugins,manual
  • apache,nginx申请的证书只用自身服务的,我们选择通常生产有Standanlone 、Webroot,Manual,DNS Plugins
    在这里插入图片描述
  • Standalone 方式: certbot 会自己运行一个 web server 来进行验证,暂时占用服务器的 80 或者 443 端口。如果我们自己的服务器上已经有 web server 正在运行 (比如 Nginx 或 Apache ),用 standalone 方式的话需要先关掉它,以免冲突。
  • Webroot 方式: certbot 会利用既有的 web server,在其 web root目录下创建隐藏文件, Let’s Encrypt 服务端会通过域名来访问这些隐藏文件,以确认你的确拥有对应域名的控制权。
  • Manual:表示手动交互模式,Certbot 有很多插件,不同的插件都可以申请证书,用户可以根据需要自行选择
  • DNS Plugins:使用各类型的DNS插件证明这个域名是属于你的,自动验证方式创建泛域名证书,不是所有的域名都能用自动验证方式创建证书,需要查看官方支持域名供应商,如阿里云是没有提供API来自动验证
三、单域名
  • standalone
sudo certbot certonly --standalone -d www.domain.com
  • webroot
sudo certbot certonly --webroot -w /var/www/live -d www.domain.com \--agree-tos \--email test@163.com
  • manual方式
sudo certbot certonly --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory --manual-public-ip-logging-ok  -d <www.your.domain> --agree-tos --email example@mail.com
四、泛域名
  • Let’s Encrypt只支持DNS方式获取泛域名
sudo certbot certonly --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory --manual-public-ip-logging-ok -d '*.<your.domain>' -d <your.domain> --agree-tos --email example@mail.com
`certonly` 表示安装模式,Certbot 有安装模式和验证模式两种类型的插件。
--manual: 表示手动交互模式,Certbot 有很多插件,不同的插件都可以申请证书,用户可以根据需要自行选择
-d: 为那些主机申请证书,如果是通配符,输入 *.xxxx.com (可以替换为你自己的域名)
--preferred-challenges: 使用 DNS 方式校验域名所有权
--server:Let's Encrypt ACME v2 版本使用的服务器不同于 v1 版本,需要显示指定。
--agree-tos:默认同意 Let’s Encrypt 的一些 agreements,不加这个参数在命令执行过程中还是会问用户是否同意;
--email:用来获取一些 Let’s Encrypt 的通知,比如证书过期之类;certonly:                       Obtain or renew a certificate, but do not install
–manual:                        Obtain certificates interactively
–preferred-challenges=dns:      Use dns to authenticate domain ownership
–server:                        Specify the endpoint to use to generate
–agree-tos:                     Agree to the ACME server’s subscriber terms
-d:                             Domain name to provide certificates for

在这里插入图片描述

  • DNS服务商配置TXT指向
    在这里插入图片描述
  • 检查DNS配置txt是否生效,dig -t txt _acme-challenge.htslqc0731.com
    在这里插入图片描述
  • 确定继续生成
    在这里插入图片描述
  • 创建成功 /etc/letsencrypt/live/example.com/下会生成五个文件
cert.pem  - Apache服务器端证书  
chain.pem  - Apache根证书和中继证书  
fullchain.pem  - Nginx所需要ssl_certificate文件  
privkey.pem - 安全证书KEY文件
README - 参数说明
Nginx环境,就只需要用到fullchain.pem和privkey.pem两个证书文件
五、删除域名证书
sudo certbot delete --cert-name example.com    # 删具体域名
sudo certbot delete     # 手动列表选择删除域名
jtserver@tlwlmy:~$ sudo certbot delete
Saving debug log to /var/log/letsencrypt/letsencrypt.logWhich certificate(s) would you like to delete?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: www.domain1.com
2: www.domain2.com
3: www.mydomain.com
4: www.domain3.com
5: www.domain4.com
6: www.domain5.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 3- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Deleted all files relating to certificate www.mydomain.com.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  • 当删除域名时候,检查一下目录域名是否删除
/etc/letsencrypt/archive
/etc/letsencrypt/live
/etc/letsencrypt/renewal
  • Wildcard certificates can only be attained using DNS validation. This is a policy decision by Let’s Encrypt.
六、证书满90天后续期
  • 自动更新ssl key脚本
#!/bin/bash# Directory where the acme client puts the generated certs
LETSENCRYPT_CERT_OUTPUT=/etc/letsencrypt/live# Create or renew certificate for the domain(s) supplied for this tool
certbot renew --dry-run --pre-hook "service nginx start" --post-hook "service nginx stop"# Cat the certificate chain and the private key together for haproxy
# for path in $(find $LETSENCRYPT_CERT_OUTPUT/* -type d -exec basename {} \;); do# cat $LETSENCRYPT_CERT_OUTPUT/$path/{fullchain.pem,privkey.pem} > /etc/haproxy/ssl/${path}.pem
for path in $(ls -d $LETSENCRYPT_CERT_OUTPUT/* | grep -o -P "[\w\.-]*$" | grep -v "README"); docat $LETSENCRYPT_CERT_OUTPUT/$path/fullchain.pem $LETSENCRYPT_CERT_OUTPUT/$path/privkey.pem > /etc/haproxy/ssl/${path}.pem
done
  • root用户crontab设置定时任务更新,每周一凌晨2点执行
0 2 * * 1  sh /etc/letsencrypt/letsencrypt-passworks.sh >> /var/log/letsencrypt/letsencrypt-passworks.log 2>&1
七、参考
  • ubuntubionic-haproxy
  • 官方文档
  • https://websiteforstudents.com/generate-free-wildcard-certificates-using-lets-encrypt-certbot-on-ubuntu-18-04/
  • https://moxo.io/blog/2018/01/30/obtain-and-renew-tls-certs-using-letsencrypt/
  • https://www.willh.cn/articles/2018/07/27/1532676216270.html
  • https://www.jesusamieiro.com/remove-revoke-a-domain-in-lets-encrypt/
  • https://medium.com/@mhagemann/correct-way-to-delete-a-certbot-ssl-certificate-e8ee123e6e01
  • Let’s Encrypt 获取 TLS 证书(Webroot + Nginx)
  • Let’s Encrypt 终于支持通配符证书了

这篇关于ubuntu 18.04 Let is Encrypt单域名和泛域名SSL证书配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/873316

相关文章

Spring配置扩展之JavaConfig的使用小结

《Spring配置扩展之JavaConfig的使用小结》JavaConfig是Spring框架中基于纯Java代码的配置方式,用于替代传统的XML配置,通过注解(如@Bean)定义Spring容器的组... 目录JavaConfig 的概念什么是JavaConfig?为什么使用 JavaConfig?Jav

Spring Boot Interceptor的原理、配置、顺序控制及与Filter的关键区别对比分析

《SpringBootInterceptor的原理、配置、顺序控制及与Filter的关键区别对比分析》本文主要介绍了SpringBoot中的拦截器(Interceptor)及其与过滤器(Filt... 目录前言一、核心功能二、拦截器的实现2.1 定义自定义拦截器2.2 注册拦截器三、多拦截器的执行顺序四、过

springboot的controller中如何获取applicatim.yml的配置值

《springboot的controller中如何获取applicatim.yml的配置值》本文介绍了在SpringBoot的Controller中获取application.yml配置值的四种方式,... 目录1. 使用@Value注解(最常用)application.yml 配置Controller 中

springboot中配置logback-spring.xml的方法

《springboot中配置logback-spring.xml的方法》文章介绍了如何在SpringBoot项目中配置logback-spring.xml文件来进行日志管理,包括如何定义日志输出方式、... 目录一、在src/main/resources目录下,也就是在classpath路径下创建logba

C++多线程开发环境配置方法

《C++多线程开发环境配置方法》文章详细介绍了如何在Windows上安装MinGW-w64和VSCode,并配置环境变量和编译任务,使用VSCode创建一个C++多线程测试项目,并通过配置tasks.... 目录下载安装 MinGW-w64下载安装VS code创建测试项目配置编译任务创建 tasks.js

Nginx概念、架构、配置与虚拟主机实战操作指南

《Nginx概念、架构、配置与虚拟主机实战操作指南》Nginx是一个高性能的HTTP服务器、反向代理服务器、负载均衡器和IMAP/POP3/SMTP代理服务器,它支持高并发连接,资源占用低,功能全面且... 目录Nginx 深度解析:概念、架构、配置与虚拟主机实战一、Nginx 的概念二、Nginx 的特点

2025最新版Android Studio安装及组件配置教程(SDK、JDK、Gradle)

《2025最新版AndroidStudio安装及组件配置教程(SDK、JDK、Gradle)》:本文主要介绍2025最新版AndroidStudio安装及组件配置(SDK、JDK、Gradle... 目录原生 android 简介Android Studio必备组件一、Android Studio安装二、A

前端Visual Studio Code安装配置教程之下载、汉化、常用组件及基本操作

《前端VisualStudioCode安装配置教程之下载、汉化、常用组件及基本操作》VisualStudioCode是微软推出的一个强大的代码编辑器,功能强大,操作简单便捷,还有着良好的用户界面,... 目录一、Visual Studio Code下载二、汉化三、常用组件1、Auto Rename Tag2

Apache服务器IP自动跳转域名的问题及解决方案

《Apache服务器IP自动跳转域名的问题及解决方案》本教程将详细介绍如何通过Apache虚拟主机配置实现这一功能,并解决常见问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,... 目录​​问题背景​​解决方案​​方法 1:修改 httpd-vhosts.conf(推荐)​​步骤

SpringBoot18 redis的配置方法

《SpringBoot18redis的配置方法》本文介绍在SpringBoot项目中集成和使用Redis的方法,包括添加依赖、配置文件、自定义序列化方式、使用方式、实际使用示例、常见操作总结以及注意... 目录一、Spring Boot 中使用 Redis1. 添加依赖2. 配置文件3. Redis 配置类