推荐一个制作 https 证书的工具 Certbot

4,488 阅读2分钟

最近一直扎根公司,连续加班,忙于工作,好久没能静下来写写东西了。

刚好前段时间给我同事布置个生成 https 证书的任务,发现很多人都是寻求于阿里云、七牛等国内大厂提供的免费或者付费证书。

但如果这些大厂不提供服务了呢?所以我们有必要自己制作证书。

所以今天给大家推荐一个工具 —— 「certbot」,可以快速生成证书,而且还可以和 apache、nginx 等完美结合使用。

certbot 可以满足常规的软件和服务系统:

certbot

Certbot is an easy-to-use automatic client that fetches and deploys SSL/TLS certificates for your webserver. Certbot was developed by EFF and others as a client for Let’s Encrypt and was previously known as “the official Let’s Encrypt client” or “the Let’s Encrypt Python client.” Certbot will also work with any other CAs that support the ACME protocol.

摘自:certbot.eff.org/about/

简单的说,就是 Let's Encrypt 这个免费、自动化、开放的证书签发服务的客户端工具,是用 Python 开发的。

接下来通过结合 CentOS 7 和 Nginx 环境来说说如何安装使用 certbot。

安装 pyOpenSSL

根据官网 (certbot.eff.org/#centosrhel…) 的步骤来安装 certbot,发现会报 pyOpenSSL 版本低的问题,所以首先需要安装 pyOpenSSL 最新版:

1. 先卸载 pyOpenSSL

sudo yum erase pyOpenSSL

2. 在 http://rpm.pbone.net/index.php3/stat/2/simple/2 搜 pyOpenSSL

3. 选择一个下载源下载:

wget ftp://mirror.switch.ch/pool/4/mirror/centos/7.4.1708/cloud/x86_64/openstack-ocata/python2-pyOpenSSL-16.2.0-3.el7.noarch.rpm

4. 安装

sudo rpm -Uvh pyOpenSSL-0.15.1-1.el7.noarch.rpm

安装 certbot

只要一条命令即可:

sudo yum install certbot certbot-nginx

使用 certbot

使用也很方便,只要输入命令,然后根据提示即可:

certbot --nginx

然后,让你选择哪个域名需要 https 协议的:

不如所料的成功了:

看看运行效果吧:

最后根据官网的提示,需要做个定时器来时不时 renew 下:

0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew 

总结

因为时间关系,没有尝试使用 certbot 的其它功能,但对于如何生成 https 证书的小白来说,我觉得 certbot 提供极大的便利,当然如何自己徒手生成证书,或者使用 Let's Encrypt 生成证书,我相信市面上的教程很多,这里就不再赘述了。

如果你觉得 certbot 还不错,你也可以试试哦~~~

补充

解决Received 1 certificate(s), first certificate had names 的问题

// centos 6.8 的环境下
sudo ./certbot-auto --nginx -d git.***.com 

「完」


coding01 期待您继续关注

qrcode


也很感谢您能看到这了

qrcode