白嫖免费的通配符ssl域名证书

let’encrypt 免费的ssl通配符证书提供服务商,致力于推广网络安全。

众所周知,没有ssl证书的网站,所有数据传输在网上都是明文的,相当于裸奔,容易被一些恶意的程序劫持,比如连接了不安全的wifi,从而造成个人密码,信息的泄漏。

如果从事后端开发,或者运维服务的同学都知道,一般云服务商都提供一些代理ssl证书购买服务,实际的证书提供商如赛门铁克,dc等等,证书从单域名到通配符域名,价格不等,通常单域名证书稍微便宜些,大约一年几百上千的样子,通配符证书一年要上万左右,而且通常需要技术人员手动一年一换,并不方便。同时,也有一些会提免费一年的单域名证书,但是出了问题的话并不理赔(与付费证书的区别)

首先说明单域名证书与通配符证书的区别:

单域名证书,顾名思义,只适用于单个二级域名,假设通常我们购买域名为:abc.com(姑且称其为一级域名,但并不准确,此处不讨论),然后通过域名解析,将blog.abc.com解析到了服务器地址,则blog.abc.com就是一个单域名,同理shop.abc.com也是一个单域名,都是二级域名,而所有的二级域名合在一起,就用*(通配符)来代替,blog和shop都属于*,所以单域名证书只对申请时指定的那个域名有效,而通配符证书,则对所有的二级域名生效。

举个例子:现在我申请了一个单域名证书blog.abc.com,那么,这个证书只能配置给blog.abc.com用,而如果给shop.abc.com使用,则浏览器会提示不安全,证书无效。但是,如果我申请了*.abc.com这个通配符证书,则都可以给blog.abc.com,shop.abc.com使用,一个搞定所有(能不能给123.blog.abc.com使用?似乎不行,这已经是三级域名了,域名分级以.为分隔,*只能管到下一级,不能管下下级,如果想管,同理申请*.blog.abc.com,反正阿里云的证书是这样)

安装 git clone https://github.com/letsencrypt/letsencrypt

下载完后,最好将此文件夹移到类似/usr/local/bin之类的系统文件夹,并给与高级权限,否则下面的命令可能无法执行成功

./certbot-auto certonly  -d *.你的域名 --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory

如果上面报错

OSError: Command /opt/eff.org/certbot/venv/bin/python2.7 - setuptools pip wheel failed with error code 1

解决问题

卸载virtualenv: pip  uninstall  virtualenv

再安装virtualenv : pip  install  virtualenv==15.1.0

输出

ackage gcc-4.8.5-36.el7_6.2.x86_64 already installed and latest version
Package augeas-libs-1.4.0-6.el7_6.1.x86_64 already installed and latest version
Package 1:openssl-1.0.2k-16.el7_6.1.x86_64 already installed and latest version
Package 1:openssl-devel-1.0.2k-16.el7_6.1.x86_64 already installed and latest version
Package libffi-devel-3.0.13-18.el7.x86_64 already installed and latest version
Package redhat-rpm-config-9.1.0-87.el7.centos.noarch already installed and latest version
Package ca-certificates-2018.2.22-70.0.el7_5.noarch already installed and latest version
Package python-devel-2.7.5-77.el7_6.x86_64 already installed and latest version
Package python-virtualenv-15.1.0-2.el7.noarch already installed and latest version
Package python-tools-2.7.5-77.el7_6.x86_64 already installed and latest version
Package python2-pip-8.1.2-8.el7.noarch already installed and latest version
Nothing to do
Creating virtual environment...
Installing Python packages...
Installation succeeded.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 531833XXX@qq.com

Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory

是否通用协议,选择是,那就是’A’

A

Would you be willing 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.

是否分享你的邮箱,否

N

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.

询问是否对域名和机器(IP)进行绑定=>需要同意

Y

证书续签

注:证书在到期前30天才会续签成功,但为了确保证书在运行过程中不过期,官方建议每天自动执行续签两次;
使用crontab自动续期
···
crontab -e // 编辑定时任务
0 */12 * * * certbot renew –quiet –renew-hook “/etc/init.d/nginx reload”

(说明:–renew-hook是指,如果更新成功的回调,则重启nginx服务,因为替换证书需要重启服务后才生效,所以,如果使用了像apache,tomcat之类的服务,就改成对应的服务重启命令)

证书保存的路径[配置nginx需要用到的]

/etc/letsencrypt/live/you.cn/fullchain.pem
/etc/letsencrypt/live/you.cn/privkey.pem

取消证书

可以使用一下命令取消刚刚生成的密匙,也就是以上的反操作:

certbot revoke --cert-path /etc/letsencrypt/live/you.cn/cert.pem
certbot delete --cert-name you.cn

如果自动续签失败,可能是无法验证域名所有者的问题,需要添加dns验证记录,但是手动的话很麻烦,以下提供云服务商自动添加的机制

https://github.com/ywdblog/certbot-letencrypt-wildcardcertificates-alydns-au

具体看readme

过了一段时间,证书又没更新= =,然后手动执行,发现爆如下错误:

Couldn’t download https://raw.githubusercontent.com/certbot/certbot/v1.11.0/letsencrypt-auto-source/letsencrypt-auto. <urlopen error [Errno 104] Connection reset by peer>

好吧gfw发威了

修改/etc/hosts

添加 199.232.4.133 raw.githubusercontent.com 即可

2021-1-7 发现,证书虽然是有效的,但是浏览器仍然提示不安全,即使重启nginx,依然不行,包括手机端访问也是如此,淦!

然后提示

Your system is not supported by certbot-auto anymore.

Certbot will no longer receive updates.

Please visit https://certbot.eff.org/ to check for other alternatives.

Saving debug log to /var/log/letsencrypt/letsencrypt.log

好吧,下载的certbot-auto已经不再支持我的系统(Ubuntu18.04 lts),让我访问https://certbot.eff.org/这个网站解决问题

第一步选择自己的webserver和系统,我选的nginx和Ubuntu18.04 lts

第二步,往下翻,按步骤的命令一步一步往下安装

即可

发表评论

邮箱地址不会被公开。 必填项已用*标注