開發微信服務號和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