chenzhao

  • java
  • iOS
  • IT
知识积累
不积跬步无以至千里
  1. 首页
  2. iOS
  3. 正文

免费SSL证书Let's Encrypt(certbot)安装使用

2016年 11月 9日 72点热度 0人点赞 0条评论

Let's Encrypt https 证书
使用
##安装方法:
如果是CentOS 6,先执行: yum install epel-release

cd /root/
wget https://dl.eff.org/certbot-auto --no-check-certificate
chmod +x ./certbot-auto
./certbot-auto -n

单域名生成证书:


./certbot-auto certonly --email 邮箱地址 --agree-tos --webroot -w /home/www/网站目录  -d www.chenzhao.date

多域名单目录生成单证书: (即一个网站多个域名使用同一个证书)

./certbot-auto certonly --email 邮箱地址 --agree-tos --webroot -w /home/www/网站目录 -d www.chenzhao.date -d chenzhao.date

注: 多个就-d 跟域名 加后面

多域名多目录生成多个证书: (即一次生成多个域名的多个证书)

./certbot-auto certonly --email 邮箱地址 --agree-tos --webroot -w /home/www/网站目录 -d www.chenzhao.date -d chenzhao.date -w /home/www/新网站文件地址 -d chenzhao.pro -d www.chenzhao.pro
./certbot-auto certonly --email czboosj@gmail.com --agree-tos --webroot -w /var/www/chenzhao.date -d www.chenzhao.date -d chenzhao.date

提示:
IMPORTANT NOTES:

  • Congratulations! Your certificate and chain have been saved at
    /etc/letsencrypt/live/www.chenzhao.date/fullchain.pem. Your cert will
    expire on 2016-10-01. To obtain a new or tweaked version of this
    certificate in the future, simply run certbot-auto again. To
    non-interactively renew all of your certificates, run
    "certbot-auto renew"
  • If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
N多确定啥的一路下来 大致就这些就是ok 的
证书在
/etc/letsencrypt/live/根据你的域名生成的地址/

##证书续期
cerrbot的续期比原来的更加简单,因为证书只有90天,所以建议使用 crontab 进行自动续期:

crontab 里加上如下规则:

0 3 */5 * * /root/certbot-auto renew 

下面的是在用规则

* */1 * * * /root/certbot-auto renew --quiet --renew-hook "systemctl restart nginx.service"

这样每5天就会执行一次续期操作。当然时间也可以自行进行调整,建议别太频繁,因为他们都有请求次数的限制。

一、Crontab的安装
1、CentOS下面安装Crontab

yum install vixie-cron crontabs      //安装Crontab

chkconfig crond on                //设为开机自启动
service crond start                 //启动

7 上面

1. 查看cron的状态,设为开机启动
systemctl status crond (查看状态) systemctl enable crond (设为开机启动)
$ systemctl start crond (启动crond服务)

说明:vixie-cron软件包是cron的主程序;crontabs软件包是用来安装、卸装、 或列举用来驱动 cron 守护进程的表格的程序

二、Crontab使用方法

1、查看crontab定时执行任务列表

crontab -l

2、添加crontab定时执行任务

crontab -e
在里面写上命令
具体命令搜索下以后

我遇到问题是Nginx 证书配置问题

https://mozilla.github.io/server-side-tls/ssl-config-generator/ 一个配置生成地址

生成后主要修改的地方

server {  
    listen 443 ssl http2;
    ....
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_dhparam /etc/nginx/ssl/dhparam.pem;

    ssl_trusted_certificate /etc/letsencrypt/live/example.com/root_ca_cert_plus_intermediates;

    resolver <IP DNS resolver>;
    ....
}

这6行中,部分文件还不存在,逐个说明。

首先是第一行 listen 443 ssl http2; 作用是启用 Nginx 的 ngxhttpv2_module 模块 支持 HTTP2,Nginx 版本需要高于 1.9.5,且编译时需要设置 --with-http_v2_module 。Arch Linux 的 Nginx 安装包中已经编译了这个模块,可以直接使用。如果你的 Linux 发行版本中的 Nginx 并不支持这个模块,可以自行 Google 如何加上。

ssl_certificate 和 ssl_certificate_key ,分别对应 fullchain.pem 和 privkey.pem,这2个文件是之前就生成好的证书和密钥。

ssl_dhparam 通过下面命令生成:

$ sudo mkdir /etc/nginx/ssl
$ sudo openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048

(可选 反正我没弄)ssl_trusted_certificate 需要下载 Let's Encrypt 的 Root Certificates,不过根据 Nginx 官方文档 所说,ssl_certificate 如果已经包含了 intermediates 就不再需要提供 ssltrustedcertificate 了。这一步可以省略:

$ cd /etc/letsencrypt/live/example.com
$ sudo wget https://letsencrypt.org/certs/isrgrootx1.pem
$ sudo mv isrgrootx1.pem root.pem
$ sudo cat root.pem chain.pem > root_ca_cert_plus_intermediates

resolver 的作用是 “resolve names of upstream servers into addresses”, 在這個配置中,resolver 是用來解析 OCSP 服務器的域名的,建议填写你的 VPS 提供商的 DNS 服务器,例如我的 VPN 在 Linode,DNS服务器填写:

resolver 106.187.90.5 106.187.93.5;
ip 和分析出来的dns 地址 VPS 服务商的 当时差点忘记
重启nginx
centos 7 重启命令
sudo systemctl restart nginx

在加上上面的自动获取证书应该ok了, 还有待考验

标签: 暂无
最后更新:2022年 11月 11日

陈昭

IT 程序员

打赏 点赞
< 上一篇
下一篇 >

文章评论

取消回复

COPYRIGHT © 2022 chenzhao. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang