使用 acme.sh 申请和管理 免费SSL 证书:告别 certbot 的繁琐

发布于:2025-02-23 ⋅ 阅读:(15) ⋅ 点赞:(0)

使用 acme.sh 申请和管理 SSL 证书:告别 certbot 的繁琐

引言

  • 介绍 SSL 证书的重要性
  • 传统 certbot 的痛点(如 live 目录、复杂的配置)
  • acme.sh 的优势(轻量、灵活、自动化)

一、acme.sh 简介

  1. 什么是 acme.sh
  2. acme.sh 的主要特点
    • 支持多种 DNS 服务商
    • 自动化续期
    • 直接指定证书路径
    • 无需额外依赖

二、安装 acme.sh

  1. 基本安装

    curl https://get.acme.sh | sh -s email=your_email@example.com
    source ~/.bashrc
    
  2. 国内用户安装(解决网络问题)

    git clone https://gitee.com/neilpang/acme.sh.git
    cd acme.sh
    ./acme.sh --install -m your_email@example.com
    source ~/.bashrc
    

三、配置阿里云 DNS

  1. 获取阿里云 AccessKey
  2. 设置环境变量
    export Ali_Key="your_aliyun_access_key"
    export Ali_Secret="your_aliyun_access_secret"
    

四、申请 SSL 证书

  1. 创建证书存放目录

    mkdir -p /www/server/panel/vhost/cert/example.com
    
  2. 申请证书

    acme.sh --issue --dns dns_ali \
      -d example.com \
      -d *.example.com \
      --certpath /www/server/panel/vhost/cert/example.com/cert.pem \
      --keypath /www/server/panel/vhost/cert/example.com/privkey.pem \
      --fullchainpath /www/server/panel/vhost/cert/example.com/fullchain.pem
    

五、配置自动续期

  1. 安装证书并设置自动更新

    acme.sh --install-cert -d example.com \
      --certpath /www/server/panel/vhost/cert/example.com/cert.pem \
      --keypath /www/server/panel/vhost/cert/example.com/privkey.pem \
      --fullchainpath /www/server/panel/vhost/cert/example.com/fullchain.pem \
      --reloadcmd "systemctl reload nginx"
    
  2. 检查自动续期配置

    crontab -l
    

六、Nginx 配置示例nginx

server {
listen 443 ssl;
server_name example.com .example.com;
ssl_certificate /www/server/panel/vhost/cert/example.com/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/example.com/privkey.pem;


七、常见问题解答

  1. 如何查看证书列表?

    acme.sh --list
    
  2. 如何查看证书信息?

    acme.sh --info -d example.com
    
  3. 如何手动续期证书?

    acme.sh --renew -d example.com
    
  4. 如何删除证书?

    acme.sh --remove -d example.com
    

八、总结

  • acme.sh 的便捷性和灵活性
  • 推荐使用 acme.sh 替代 certbot
  • 鼓励读者尝试并分享经验