SSL证书生成

  1. 安装 acme.sh

    curl https://get.acme.sh | sh -s email=替换你的邮箱
    错误:github 443
    解决方案:生成ssh,github上添加key,见参考连接
    错误:命令不生效 -bash: acme.sh: command not found
    解决方案:source ~/.bashrc
  2. 提交证书申请(要同时设置多域名,加-d 就好)

    acme.sh --issue --dns -d newyetai.com -d *.newyetai.com --yes-I-know-dns-manual-mode-enough-go-ahead-please
  3. 添加域名解析(类型 TXT),上一步会生成 Domain/Txt value

  4. 确认申请,重新生成证书

    acme.sh --renew --dns -d newyetai.com -d *.newyetai.com --yes-I-know-dns-manual-mode-enough-go-ahead-please
  5. 以上是 dns 手动添加 txt 解析,以下以阿里云 key+secret 方式添加 txt 解析

    1.首先获取你的阿里云API Key: https://ak-console.aliyun.com/#/accesskey
    2.服务器执行
    export Ali_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
    export Ali_Secret="jlsdflanljkljlfdsaklkjflsa"
    3.证书申请: acme.sh --issue --dns dns_ali -d newyetai.com -d *.newyetai.com
  6. 安装证书

    acme.sh --installcert -d newyetai.com -d *.newyetai.com --keypath /etc/letsencrypt/live/newyetai.com/newyetai.com.key --fullchainpath /etc/letsencrypt/live/newyetai.com/newyetai.com.key.pem --reloadcmd "service nginx force-reload"
    /etc/ssl/newyetai_all/newyetai_all.key.pem
    /etc/ssl/newyetai_all/newyetai_all.key
    其中service nginx force-reload是为了在让acme自动更新时候能够重启nginx使得证书生效
  7. 删除

    acme.sh --remove -d newyetai.com -d *.newyetai.com
  8. nginx 配置

    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/newyetai.com/newyetai.com.key.pem;
    ssl_certificate_key /etc/letsencrypt/live/newyetai.com/newyetai.com.key;
  9. 强化加密

    openssl dhparam -out ./dhparam.pem 2048
    nginx配置 ssl_dhparam dhparam.pem地址
  10. nginx 重启

    测试 : nginx -t
    重启:nginx -s reload
  11. 证书更新:Let's Encrypt 的证书有效期是 90 天的,需要定期重新申请,不过 acme 在安装的时候就已经设置了自动更新,所以这一步不用关心,很省心。

    查看定时任务:crontab -l
    调整定时任务: crontab -e
    0 0 1 */2 * "/root/.acme.sh"/acme.sh --cron -f --home "/root/.acme.sh" > /dev/null
    手动renew一下证书:acme.sh --cron -f
  12. 设置软件自动更新:目前由于 acme 协议和 letsencrypt CA 都在频繁的更新, 因此 acme.sh 也经常更新以保持同步.所以为了省心省力,最好还是设置一下软件的自动更新

    acme.sh --upgrade --auto-upgrade

关于Let's Encrypt根证书过期,在某些情况下 OpenSSL 会选择已经过期的 DST Root CA X3 根证书

  1. Let's Encrypt证书链:

    * 链1(已过期):
    DST Root CA X3 (1) -> ISRG Root X1 (2) -> R3 (3) -> youside.com (4)
    * 链2:
    ISRG Root X1 (5) -> R3 (3) -> youside.com (4)
  2. 最直观的方法就是查看本地连接到 LE 官网的报文,不报证书错误即没问题。

  3. 自带的,或通过系统官方源安装的 OpenSSL 版本为 1.0.X,当然 Debian 9 这个挂羊头卖狗肉,Ubuntu 16.04 这个修修补补还能用的俩奇葩早已超脱三界之外,查看 OpenSSL 版本命令如下:

    • openssl version
  4. 系统未内置新的根证书“ISRG_Root_X1”(说明系统版本太旧),查询该证书是否内置的方法如下。

    • Debian/Ubuntu 输入:
    dpkg-reconfigure ca-certificates

    选择“yes”回车,翻页查找,如果该证书存在,按 Esc 退出:

    • CentOS,输入:
    cat /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt | grep -E "ISRG_Root_X1"

    如果有结果输出,说明已内置,反之则未内置。

解决方案:

  1. (docker内系统是这个版本)Debian 8/9 、Ubuntu 14.04 解决方法 在证书配置文件中,删除“DST_Root_CA_X3”证书,并重载根证书配置:

    sed -i '/^mozilla\/DST_Root_CA_X3/s/^/!/' /etc/ca-certificates.conf && update-ca-certificates -f

    警告,此操作会使系统失去与仅安装了“DST_Root_CA_X3”证书的旧设备的兼容性,请谨慎操作。

  2. CentOS 6/7 解决方法: 删除系统内置的,受信任的根证书目录中的“DST_Root_CA_X3”证书:

    rm -rf /etc/ca-certificates/trust-source/DST_Root_CA_X3.pem

    更新证书信任列表配置:

    update-ca-trust

    警告,此操作会使系统失去与仅安装了“DST_Root_CA_X3”证书的旧设备的兼容性,请谨慎操作。

ps:

阿里云VOD需要将上面的内容配置上去,否则无法使用https的cdn。
域名证书由106服务器生成,其他服务器nginx需要就从这两台服务器拷贝

另一种生成证书方式

参考

Connecting to GitHub with SSH

Adding a new SSH key to your GitHub account

acme.sh 生成证书教程

acme.sh 自动更新

Let's Encrypt 出现证书不受信任已过期的解决方案