开发微信服务号和IOS访问服务器端常用到https加密传输,如今讲解一下,如何得到Lets Encrypt免费的ssl证书,并在nginx里配置使用。python
Certbot是一个EPEL安装包,若是没有配置EPEL库,须要提早将库配置好。nginx
运行如下命令安装Certbot:服务器
$ sudo yum install certbot-nginx
$ sudo certbot --authenticator standalone --installer nginx --pre-hook "nginx -s stop" --post-hook "nginx"
生成过程当中须要输入域名,域名要提早进行解析。微信
certbot会在/etc/letsencrypt/live/目录下生成一个域名的目录,而后修改对应的nginx的配置。dom
ssl_certificate "/etc/letsencrypt/live/{域名}/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/{域名}/privkey.pem";post
Let's Encrypt证书有效期为90天,为了保证在过时前更新证书,Certbot提供了更新证书有效期的功能。使用如下功能能够进行更新:加密
$ sudo certbot renew --dry-run
也能够使用crontab自动更新证书有效期。spa
0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew