使用Lets Encrypt 生成nginx ssl证书

开发微信服务号和IOS访问服务器端常用到https加密传输,如今讲解一下,如何得到Lets Encrypt免费的ssl证书,并在nginx里配置使用。python

1. 安装Certbot客户端

Certbot是一个EPEL安装包,若是没有配置EPEL库,须要提早将库配置好。nginx

运行如下命令安装Certbot:服务器

 

$ sudo yum install certbot-nginx

2.使用Certbot生成证书

 

$ sudo certbot --authenticator standalone --installer nginx --pre-hook "nginx -s stop" --post-hook "nginx"

生成过程当中须要输入域名,域名要提早进行解析。微信

3.修改nginx配置

certbot会在/etc/letsencrypt/live/目录下生成一个域名的目录,而后修改对应的nginx的配置。dom

ssl_certificate "/etc/letsencrypt/live/{域名}/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/{域名}/privkey.pem";
post

4.证书的更新

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
相关文章
相关标签/搜索