• acme.sh获取证书


    acme.sh获取证书

    1. 一键安装

      curl https://get.acme.sh | sh

    2. 安装完成后,通过命令crontab -l查看

      [root@iZbp1bfgy47a5uv2p4ydheZ www.tangwx.site]# crontab -l
      42 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
      
      • 1
      • 2

      发现已经存在定时任务了!(自动更新证书的作用)

    3. 登录阿里云,按照下图方式创建用户,记录下ID和Secret。另外再授权一下。

    4. 配置一下环境变量

    [root@iZbp1bfgy47a5uv2p4ydheZ ~]# export Ali_Key="****"
    [root@iZbp1bfgy47a5uv2p4ydheZ ~]# export Ali_Secret="******"
    
    • 1
    • 2
    1. 执行命令(必须先执行第4步)
    acme.sh --issue --dns dns_ali -d tangwx.site -d *.tangwx.site
    
    • 1

    最终输出如下所示信息就表示证书申请成功了

    QE+GH2V131/WqC960Wm7BKVQcLGBpihVERnwpNRhfORdLkO/9vIjud5W2Fx4NBJL
    URHFblPbvY421/mUFW/ffgXctY6ilLzGsJyVwRPliwVpPtLnbdZQLNSyX8bi2dUf
    bP1rLcuZExA8soCfkEd/grgHyq0M+QTf
    -----END CERTIFICATE-----
    [2022年 08月 24日 星期三 15:45:18 CST] Your cert is in: /root/.acme.sh/tangwx.site/tangwx.site.cer
    [2022年 08月 24日 星期三 15:45:18 CST] Your cert key is in: /root/.acme.sh/tangwx.site/tangwx.site.key
    [2022年 08月 24日 星期三 15:45:18 CST] The intermediate CA cert is in: /root/.acme.sh/tangwx.site/ca.cer
    [2022年 08月 24日 星期三 15:45:18 CST] And the full chain certs is there: /root/.acme.sh/tangwx.site/fullchain.cer
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    1. 拷贝证书到nginx目录
    acme.sh --install-cert -d tangwx.site \
    --key-file /usr/local/nginx/conf/ssl2/key.pem \
    --fullchain-file /usr/local/nginx/conf/ssl2/cert.pem \
    --reloadcmd  "service nginx force-reload"
    
    • 1
    • 2
    • 3
    • 4

    注意:虽然第5步生成的key、cert、full chain certs文件格式是tangwx.site.key、tangwx.site.cer、fullchain.cer,但是通过上述命令拷贝后重命名了。

    tangwx.site.key -> key.pem && fullchain.cer -> cert.pem

    (一个小提醒, 这里用的是 service nginx force-reload, 不是 service nginx reload, 据测试, reload 并不会重新加载证书, 所以用的 force-reload)

    --install-cert命令可以携带很多参数, 来指定目标文件. 并且可以指定 reloadcmd, 当证书更新以后, reloadcmd会被自动调用,让服务器生效.(即配合第二步介绍的cron定时更新证书)

    1. 修改nginx的配置,让它指向最新的ssl证书,然后重启nginx即可
    sl_certificate /usr/local/nginx/conf/ssl2/cert.pem;
    ssl_certificate_key /usr/local/nginx/conf/ssl2/key.pem;
    
    • 1
    • 2
    1. 自动更新acme.sh
    acme.sh  --upgrade  --auto-upgrade
    
    • 1
    可以随时关闭自动更新: acme.sh --upgrade  --auto-upgrade  0
    
    • 1
    1. 官方文档地址

    https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E

  • 相关阅读:
    Windows下的Linux子系统(WSL)
    Go的数据结构(感谢韩老师)
    Java 面试题大集合,2019最新最常见面试题加答案
    MATLAB制图代码【第二版】
    我测试用的mark down教程
    日志@Slf4j介绍使用及配置等级
    for(auto count : counts)
    MySQL入门 - 数据分组之 group by
    快递查询 根据城市名称筛选最后站点城市的单号
    ctfhub -afr -1 2 3
  • 原文地址:https://blog.csdn.net/twx843571091/article/details/126540240