找回密码
 立即注册
首页 业界区 业界 使用acme自动管理部署ssl

使用acme自动管理部署ssl

虾氲叱 2025-9-28 18:15:44
具体操作流程
第一步:备份现有配置
备份nginx配置
  1. cp /etc/nginx/conf.d/yunche.conf /etc/nginx/conf.d/yunche.conf.backup.$(date+%Y%m%d)
复制代码
备份现有SSL证书
  1. cp -r /data/nginx/ssl /data/nginx/ssl.backup.$(date +%Y%m%d)
复制代码
第二步:安装acme.sh
  1.   curl https://get.acme.sh | sh -s email=你的邮箱@example.com
  2.   source ~/.bashrc
复制代码
第三步:配置腾讯云DNS API
  1.   export Tencent_SecretId="你从腾讯云获取的SecretId"
  2.   export Tencent_SecretKey="你从腾讯云获取的SecretKey"
复制代码
保存到环境变量
  1.   echo 'export Tencent_SecretId="你的SecretId"' >> ~/.bashrc
  2.   echo 'export Tencent_SecretKey="你的SecretKey"' >> ~/.bashrc
复制代码
第四步:申请Let's Encrypt证书
  1.   # 先测试模式
  2.   ~/.acme.sh/acme.sh --issue --test \
  3.     -d wx.fengyunyunche.com \
  4.     --dns dns_tencent
复制代码
  1.   # 测试成功后申请正式证书
  2.   ~/.acme.sh/acme.sh --issue \
  3.     -d wx.fengyunyunche.com \
  4.     --dns dns_tencent
复制代码
第五步:部署证书到你的目录
  1.   ~/.acme.sh/acme.sh --install-cert -d wx.fengyunyunche.com \
  2.     --key-file /data/nginx/ssl/wx.fengyunyunche.com.key \
  3.     --fullchain-file /data/nginx/ssl/wx.fengyunyunche.com_bundle.crt \
  4.     --reloadcmd "nginx -t && nginx -s reload"
复制代码
第六步:验证自动续期
  1.   # 查看续期任务是否已设置
  2.   crontab -l | grep acme
复制代码
  1.   # 测试续期(dry run,不会真的续期)
  2.   ~/.acme.sh/acme.sh --cron --home ~/.acme.sh --force
复制代码
操作要点

  • 无需修改nginx配置:证书路径保持不变,只是证书内容会自动更新
  • 不影响现有服务:整个过程只是替换证书文件,不重启服务
  • 保留原文件结构:继续使用/data/nginx/ssl/目录
  • 自动续期:90天有效期,60天后自动续期
需要你提供的信息

  • 腾讯云API密钥:
    - 登录腾讯云控制台
    - 访问管理 → API密钥管理
    - 新建密钥获取SecretId和SecretKey
  • 邮箱地址:用于Let's Encrypt通知
安全提醒

  • 操作前确保域名的DNS确实在腾讯云解析
  • 每一步操作后都用nginx -t测试配置
  • 如果出错,可以快速恢复备份:
    cp /data/nginx/ssl.backup.$(date +%Y%m%d)/* /data/nginx/ssl/
    nginx -s reload

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册