侧边栏壁纸
博主头像
TLYAN

只要芝麻,不要西瓜.............纯大神之作
古人有雲:吃得苦中苦方為人上人

  • 累计撰写 113 篇文章
  • 累计收到 5 条评论
申请Let‘s Encrypt免费SSL证书、自动化续签证书
9个月前 248阅读 0评论 0点赞

一、环境(如果是宝塔跳过

安装证书的环境为Centos + Nginx,如果没有安装Nginx则需要先安装。



二、申请流程(如果是宝塔跳过,有建站的跳过

1、开放80和443端口


firewall-cmd --permanent --add-port=80/tcp

firewall-cmd --permanent --add-port=443/tcp

firewall-cmd --reload


2、安装 certbot

使用certbot工具能够很方便的申请和续签let’s encript证书。


yum install -y epel-release

yum install -y certbot

如果执行命令报错(参考:https://www.tlyan.com/post-99.html



3.申请证书

certbot certonly --webroot -w [Web站点目录] -d [站点域名] -m [联系人email地址] --agree-tos

  如果环境是宝塔的话  certbot certonly --webroot -w /www/wwwroot/tlyan.com -d www.tlyan.com -m 153160675@qq.com --agree-tos

  [Web站点目录]          /www/wwwroot/tlyan.com   (参考实际路径

  [站点域名]                 www.tlyan.com                       实际域名

  [联系人email地址]     153160675@qq.com          (这个目前不知道有什么用


4、申请成功后,会在/etc/letsencrypt/live/{域名}/下,生成一些文件。

  image.png

    README

    cert.pem

    chain.pem

    fullchain.pem    (配置证书需要的pem)

    privkey.pem      (配置证书需要的key)



5、可以查看一下证书有效期


openssl x509 -noout -dates -in /etc/letsencrypt/live/{域名}/cert.pem

1

6、配置Nginx(参考)


ssl_certificate    /etc/letsencrypt/live/{域名}/fullchain.pem;

ssl_certificate_key    /etc/letsencrypt/live/{域名}/privkey.pem;

ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;

ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;

ssl_prefer_server_ciphers on;

ssl_session_cache shared:SSL:10m;

ssl_session_timeout 10m;

add_header Strict-Transport-Security "max-age=31536000";

error_page 497  https://$host$request_uri;

、重启Nginx


nginx -s reload



下面的待确认

三、自动化续签

1、根据需求,选择下面两句话之一


## 更新证书

certbot renew --dry-run

 

## 如果不需要返回的信息,可以用静默方式

certbot renew --quiet


2、加入crontab


crontab -e

3、加入命令(续签并重载nginx配置)


                0 10 * * 1 certbot renew --quiet && nginx -s reload


这里配置的是每周一 10点执行一次,根据个人需求更改配置即可。


版权所有:《小唐博客-唐联艳-我可以告诉你》 => 《申请Let‘s Encrypt免费SSL证书、自动化续签证书
本文地址:https://www.tlyan.com/post-100.html
除非注明,文章均为 《小唐博客-唐联艳-我可以告诉你》 原创,欢迎转载!转载请注明本文地址,谢谢。

分享本文至:

扫描二维码,在手机上阅读

评论

取消