允许EPEL仓库
$ yum -y install yum-utils $ yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional安装CertBot
$ sudo yum install certbot
certbot需要pyOpenSSL 0.14版本
pip show pyOpenSSL查看版本, centos 7.2默认安装的pyOpenSSL0.13, 运行certbot会报错
pip install pyOpenSSL==0.14
certbot在申请证书过程中,会通过访问待申请域名下面的.well-known/acme-challenge/*来验证服务是否可访问,所以需要先配置一下nginx.
在 nginx.conf加入以下配置
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
root /usr/local/nginx-1.10.1/html;
}
申请证书
参数说明
--webroot 使用webroot plugin
-w webserver的root,/usr/local/nginx-1.10.1/html这是我的nginx的webroot目录
-d 指定域名,这里是panchan.net.cn, www.panchan.net.cn
生成的证书存放在/etc/letsencrypt/live/panchan.net.cn目录下面。
自动更新证书
Let's Encrypt申请的免费证书90天会自动过期,可以使用以下命令自动续期
首先运行certbot renew --dry-run, 测试是否可以自动续期,如果返回正确,可以在cron或systemd中添加计划任务certbot renew实现自动续期。
参考资料
https://letsencrypt.org/
https://letsencrypt.org/docs/
https://certbot.eff.org/#centosrhel7-nginx