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