avatar

sunday

Sunday's Blog

  • 首页
Home 自动上传ssl证书到阿里云证书管理控制台中
文章

自动上传ssl证书到阿里云证书管理控制台中

Posted 2024-05-21 Updated 2024-05- 21
By sunday
8~10 min read

由于oss需要自定义域名启动https,但是证书需要上传到阿里云的证书控制台上,而域名证书有效期是3个月,所以写个自动脚本更新上传

vscode新建个目录cert 然后执行

cd ./cert
npm init #然后一直回车
npm i @alicloud/openapi-client @alicloud/cas20200407 @alicloud/tea-util @alicloud/tea-typescript

新建index.js文件,需准备好证书,生成证书请看:acme.sh生成证书

注意 config.endpoint 指定上传到哪里,可以到这里看填什么https://api.alibabacloud.com/product/cas

"use strict";
// This file is auto-generated, don't edit it
// Dependent modules can be viewed by downloading the module dependency file in the project or obtaining SDK dependency information in the upper right corner
const cas20200407 = require("@alicloud/cas20200407");
const OpenApi = require("@alicloud/openapi-client");
const Util = require("@alicloud/tea-util");Tea
// const Tea = require("@alicloud/tea-typescript");
const fs = require("fs");

class Client {
  /**
   * Initialize the Client with the AccessKey of the account
   * @return Client
   * @throws Exception
   */
  static createClient() {
    // The project code leakage may result in the leakage of AccessKey, posing a threat to the security of all resources under the account. The following code examples are for reference only.
    // It is recommended to use the more secure STS credential. For more credentials, please refer to: https://www.alibabacloud.com/help/en/alibaba-cloud-sdk-262060/latest/credentials-settings-5.
    let config = new OpenApi.Config({
      // Required, please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID is set.
      accessKeyId: process.env["ALIBABA_CLOUD_ACCESS_KEY_ID"],
      // Required, please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_SECRET is set.
      accessKeySecret: process.env["ALIBABA_CLOUD_ACCESS_KEY_SECRET"],
    });
    // See https://api.alibabacloud.com/product/cas.
    config.endpoint = `cas.ap-southeast-1.aliyuncs.com`;
    return new cas20200407.default(config);
  }

  static async main(args) {
    let client = Client.createClient();
    let uploadUserCertificateRequest =
      new cas20200407.UploadUserCertificateRequest({
        name: "your-custom-name",
        cert: fs.readFileSync("./fullchain.pem").toString(),
        key: fs.readFileSync("./privkey.pem").toString(),
      });
    let runtime = new Util.RuntimeOptions({});
    try {
      // Copy the code to run, please print the return value of the API by yourself.
      await client.uploadUserCertificateWithOptions(
        uploadUserCertificateRequest,
        runtime
      );
    } catch (error) {
      // Only a printing example. Please be careful about exception handling and do not ignore exceptions directly in engineering projects.
      // print error message
      console.log(error.message);
      // Please click on the link below for diagnosis.
      console.log(error.data["Recommend"]);
      Util.default.assertAsString(error.message);
    }
  }
}

exports.Client = Client;
Client.main(process.argv.slice(2));

在ubuntu服务器新增定时器,请确保服务器安装了nodejs (本站有安装教程:安装nodejs)

sudo crontab -e
#添加 每月1号凌晨3点钟执行
0 3 1 * * /usr/bin/node /path/to/index.js
#确保脚本具有可执行权限
sudo chmod +x /path/to/index.js

软件安装, 域名证书SSL, 阿里云, 软件使用
软件使用 阿里云 域名证书 软件安装
License:  CC BY 4.0
Share

Further Reading

Jul 30, 2025

申请Google oauth授权验证,并通过验证中心

1.申请一个google project https://console.cloud.google.com/projectcreate?previousPage 到这个页面申请一个项目,进入项目 然后点击左上角选择进入oauth 权限请求页面

Jul 29, 2025

Coze Studio 一键安装工具,马上开始你的AI工作流

1.clone项目,一键安装 git clone https://github.com/hst-Sunday/oneclick-coze.git cd oneclick-coze chmod +x coze-studio.sh ./coze-studio.sh 这个安装命令也支持windows11的

Jul 25, 2025

解决vscode上python代码无法解析导入

1.已经生成了虚拟环境了,如以下结构 ⏺ your-project/ ├── .gitignore ├── api/ │ └── index.py ├── requirements.txt └── .venv/ └── (虚拟环境文件) 2.vscode上显示如下

OLDER

阿里云oss部署vue3单页应用/静态文件

NEWER

vue3除index.html外,所有静态资源部署到阿里云oss上

Recently Updated

  • 多个github账号在一台电脑上如何使用呢?
  • Google Search Conosle DNS验证域名
  • 申请Google oauth授权验证,并通过验证中心
  • Coze Studio 一键安装工具,马上开始你的AI工作流
  • 解决vscode上python代码无法解析导入

Trending Tags

nginx acme 强制跳转HTTPS nodejs 代理 mac 神器 vue3 工具 docker

Contents

©2025 sunday. Some rights reserved.

Using the Halo theme Chirpy