最近做一个新加坡的项目,要用到亚马逊云服务AWS,遇到一个https的证书问题。以前国内项目都用的阿里云提供的免费https证书,直接推送到SLB完事。AWS也有同样的功能,使用ELB(负载均衡)提供免费的证书管理服务ACM,但存在一个问题,项目需要将https证书下载下来用于APP端验证,而AWS不提供证书下载。于是有人提出使用let’s encrypt的免费证书,然后我这边负责调研。

其实在2017年IOS强制使用https时就看过关于let’s encrypt的小道新闻,但没有真正关注,毕竟阿里云提供了相关服务。

首先感谢这些提供免费产品/服务的组织,let’s encrypt免费提供使用90天的证书,支持续期。看起来很完美,但实际使用过程中坑很多:

  1. let’s encrypt的证书制作过程是依赖应用服务器的,比如nginx、apache,需要能够访问到服务器的80端口。以nginx为例,需要提前安装好,并且装了SSL模块,还需要配置到环境变量中。
  2. 操作系统版本不一样都会导致证书制作出现各种异常。
  3. 最关键的是续期,如果能够自动续期,那什么问题都不是问题。如果拥有服务器的命令行权限,那么可以增加定时任务实现自动续期;但是对于没有命令行权限的服务(比如AWS ELB),只能手动处理,定期上传新证书,这其实不现实。

由于let’s encrypt官方推荐使用certbot来生成证书,下面将使用certbot进行尝试。参考https://certbot.eff.org/lets-encrypt/centosrhel7-nginx

第一步:安装certbot

sudo yum install certbot python2-certbot-nginx

其中certbot用来生成证书,python2-certbot-nginx用来将证书自动配置到nginx

执行后提示:

Failed: python-urllib3.noarch 0:1.10.2-5.el7

也就是urllib3安装失败,暂时没处理

第二步:生成证书

sudo certbot certonly --nginx

也可以使用下面的命令,直接将证书自动配置到nginx

sudo certbot --nginx

我使用的certbot certonly --nginx,执行后提示

ImportError: No module named ‘requests.packages.urllib3’

于是将urllib3删除后重新安装,再次执行

pip uninstall urllib3
pip install urllib3
sudo certbot certonly --nginx

依然报错,提示:

pkg_resources.DistributionNotFound: The ‘urllib3<1.23,>=1.21.1’
distribution was not found and is required by requests

于是指定urllib3的版本安装后再次执行

easy_install urllib3==1.21.1
sudo certbot certonly --nginx

报了其他错,提示

ImportError: ‘pyOpenSSL’ module missing required functionality. Try
upgrading to v0.14 or newer.

通过以下命令发现requests版本不一致

#    pip list 2>/dev/null | grep requests

2.18.4

#    rpm -q python2-requests --queryformat '%{VERSION}\n'

2.6.0

于是将requests版本设置为一致后再次执行:

pip install --upgrade --force-reinstall 'requests==2.6.0'
sudo certbot certonly --nginx

提示错误:(也就是找不到nginx)

Could not choose appropriate plugin: The nginx plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.",)

由于没有将nginx放到环境变量中,设置nginx软连接

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
ln -s /usr/local/nginx/conf/ /etc/nginx
sudo certbot certonly --nginx

又提示新的错误:

Could not choose appropriate plugin: The nginx plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('Nginx build is missing SSL module (--with-http_ssl_module).',)

通过nginx -V查看nginxconfigure arguments没有安装ssl模板,在nginx目录中重新构建

cd /opt/nginx-1.14.0
./configure --with-http_ssl_module
make && make install

再次检查nginx -V已经加上ssl模块。

使用sudo certbot certonly --nginx生成证书,中间需要填写email和域名,生成成功后会提示证书存放路径:

/etc/letsencrypt/live/kevin.xxx.com/fullchain.pem
/etc/letsencrypt/live/kevin.xxx.com/privkey.pem

第三步:使用证书
配置nginx:vim /opt/nginx-1.14.0/conf/nginx.conf

server {listen       443;ssl on;server_name  kevin.xxx.com;ssl_certificate /etc/letsencrypt/live/kevin.xxx.com/fullchain.pem;ssl_certificate_key /etc/letsencrypt/live/kevin.xxx.com/privkey.pem;location / {root   /opt/www/test;index  index.html index.htm;}
}

重启后即可访问,记得要开放服务器的443端口

第四步:配置自动续签

每月1号、8号和20号零点自动检查更新证书,如果证书有效期还比较长,就不会更新。证书到期前20天、10天和1天都会发送通知邮件。

echo "0 0 1,8,20 * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew" | sudo tee -a /etc/crontab > /dev/null

意思就是在/etc/crontab中加入更新证书的定时任务

可以在/var/log/letsencrypt中查看日志,检查定时任务是否执行。

Centos使用let's encrypt免费https证书(certbot)相关推荐

  1. let‘s encrypt免费https证书(certbot)

    let's encrypt免费https证书(certbot) 准备工作 访问let's encrypt官网 具体配置步骤 第一步,以具有 sudo 权限的用户身份通过​​ SSH 连接到运行您的 H ...

  2. Let‘s Encrypt 免费Https证书

    参考文章:Let's Encrypt,免费好用的 HTTPS 证书 先放官网 Let's Encrypt Let's Encrypt 是免费.自动化.开放的证书签发服务, 它得到了 Mozilla.C ...

  3. acme.sh申请Let‘s Encrypt 免费HTTPS证书

    1.安装acme.sh(新的操作流程已更新,更新时间2022-10-14) 该文档基于ubuntu 20.04操作,基本大同小异,这里附上官方文档供对比参考,如果出现其他问题的可以邮箱留言 14067 ...

  4. let‘s encrypt 免费https证书申请

    安装下载certbot https://certbot.eff.org/instructions?ws=nginx&os=ubuntuxenial 执行 certbot run -a manu ...

  5. 万由u-nas系统用上Let’s Encrypt 免费Https安全证书

    万由u-nas系统用上Let's Encrypt免费Https安全证书 ----by icarus 2019.2.25 前言: 万由的https证书是自签发的,你在外网访问的时候会显示不安全,就很烦, ...

  6. 教你快速撸一个免费HTTPS证书

    摘要: 免费 HTTPS 证书,了解一下? HTTPS 已成为业界标准,这篇博客将教你申请Let's Encrypt的免费 HTTPS 证书. 本文的操作是在 Ubuntu 16.04 下进行,使用 ...

  7. 申请Let's Encrypt通配符HTTPS证书(转)

    2019独角兽企业重金招聘Python工程师标准>>> 首先声明,转载自:https://my.oschina.net/kimver/blog/1634575,感谢原创作者,我修改了 ...

  8. 利用Certbot工具快速给网站部署Let's Encrypt免费SSL证书

    使用https证书的话,强制使用域名 很多商家也都提供免费证书,比如腾讯云提供免费一年GeoTrust DV SSL证书.Let's Encrypt永久免费但需要90天激活一次续约,当然如果要购买证书 ...

  9. K8s 中使用 cert-manager 申请免费 Https 证书

    K8s 中使用 cert-manager 申请免费 Https 证书 Intro 最近在尝试将自己的应用从自己用 kind 部署的一个 k8s 集群迁移到 Azure 的 AKS 上,其中一个问题就是 ...

最新文章

  1. [Java] grails 安装手记
  2. 什么是WeakHashMap--转
  3. dxf geojson 转换_将Geopandas中geojson文件的linestring转换为polygon
  4. udp重发机制_UDP 协议
  5. 第三次学JAVA再学不好就吃翔(part52)--String类的其他功能
  6. 使用代码创建BRF ruleset
  7. P2805-[NOI2009]植物大战僵尸【网络流,最大权闭合图】
  8. 谈谈写程序与学英语 --宋劲杉
  9. paypal创建订单后怎么获得id_新支付无国界:PayPal注册教程
  10. 面向开发者的最佳 Android 库列表
  11. 微星主板黑苹果_AMD黑苹果主机金牌装机单
  12. 多元线性回归模型矩阵推导(手推带矩阵求导法则)
  13. Microsoft.SharePoint.dll分享
  14. 农产品管理系统-毕设
  15. Python搭建QQ聊天机器人极简教程
  16. 计算机论文中期报告进展情况,自动化毕业论文中期报告进展情况怎么写
  17. Photoshop CS6 破解安装
  18. Septentrio板卡接收机连接方式
  19. javascript从入门到跑路-----小文的js学习笔记(6)-----三大流程控制语句---顺序控制、分支控制、循环控制
  20. 单实例安装elastic和启动报错解决

热门文章

  1. react梳理之(非)受控组件
  2. Python:实现前缀Knuth–Morris–Pratt 算法(附完整源码)
  3. 如何做好 H5 性能优化
  4. 第5章_使用者(User)_群组(Group)_非群组外的其他人(Other)文件权限改变
  5. 「镁客·请讲」小熊尼奥熊剑明:AR教育产品没有想象中那么容易,入坑需谨慎...
  6. Linux入门:tar、gzip、bzip2以及zip的区别
  7. docker run redis STATUS Exited (1)
  8. 2020年TI杯大学生电子设计大赛 无线运动传感器节点 作品开源( PCB、设备/服务器工程、文档、测试视频、设计报告)
  9. 垃圾回收器PS MarkSweep和serial old使用算法异同
  10. 运动----最简单经济最适合的强身健体方式