使用nginx+cerbot为网站申请ssl证书以及自动续签
安装certbot
首先ssh进服务器,添加EPEL的repository
根据自己服务器的系统添加https://fedoraproject.org/wiki/EPEL#Quickstart
1 | # CentOS 7 |
安装Certbot
1 | sudo yum install certbot python2-certbot-nginx |
修改cerbot代码使其支持中文comments
这一步是因为cerbot里读取文件默认不是unicode模式,所以如果nginx的config里有中文的comments,python会出现错误,如下图
为了解决这个问题我们需要在cerbot的parser文件里添加几行代码
1 | # 通过log得知nginxparser的位置 |
使用certbot一键为nginx申请ssl certificate
1 | sudo certbot --nginx -d 域名.com -d www.域名.com |
选择是否需要移除http流量访问并自动重新引导至https,建议选2
当出现congratulations,我们的ssl证书就已经申请好了
如果我们打开我们申请的域名的config,可以看到cerbot已经自动为我们设置好了ssl
设置cron为服务器自动续ssl证书
在shell里打开crontab文件
1 | crontab -e |
添加任务
1 | 0 12 * * * /usr/bin/certbot renew --quiet |
验证域名是否已经是ssl
进入下面网站,输入刚刚申请的域名即可测试
https://www.ssllabs.com/ssltest/
Reference:
https://certbot.eff.org/lets-encrypt/centosrhel7-nginx.html
https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/
https://fedoraproject.org/wiki/EPEL#Quickstart
https://github.com/certbot/certbot/issues/5592
https://stackoverflow.com/questions/21904536/lxml-lookuperror-unknown-encoding-uft-8/21904588
https://onepagezen.com/letsencrypt-auto-renew-certbot-apache/
test ssl: