使用acme自動管理部署ssl
具體操作流程
第一步:備份現有配置
備份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

浙公網安備 33010602011771號