1、安装epel源和Certbot客户端(选择一种)

yum -y install epel-release
yum -y install certbot-apache #apache提供web服务
yum -y install certbot-nginx #nginx提供web服务

2、获取证书(选择一种)

certbot --apache -d ifshow.com -d www.ifshow.com #apache提供web服务
certbot --nginx -d ifshow.com -d www.ifshow.com #nginx提供web服务

在 /etc/letsencrypt/live/ 会生成对应域名ifshow的文件夹,里面有指向证书的快捷方式。

注意:域名A记录正确解析到服务器IP,并且web服务配置正确,网站可以正常访问(80和443端口均可)。

3、在站点添加ssl证书,nginx为例:

server {
 server\_name ifshow.com www.ifshow.com;
 listen 443;
 ssl on;
 ssl\_certificate /etc/letsencrypt/live/ifshow.com/fullchain.pem;
 ssl\_certificate\_key /etc/letsencrypt/live/ifshow.com/privkey.pem;
 ...

4、获得证书只有3个月有效期,可以通过cron定期自动更新证书:

yum -y install cronie
systemctl start crond.service
systemctl enable crond.service
crontab -e

添加一行(每个月1号凌晨2:30自动执行证书强制更新操作)后保存退出。

30 2 1 * * certbot renew --renew-by-default --quiet