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

May 21, 2024

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

由于oss需要自定义域名启动https,但是证书需要上传到阿里云的证书控制台上,而域名证书有效期是3个月,所以写个自动脚本更新上传 vscode新建个目录cert 然后执行 cd ./cert npm init #然后一直回车 npm i @alicloud/openapi-client @alic

Jan 29, 2022

通过Certbot申请域名通配符

安装snap以centos7为例子1.sudo yum install epel-release2.sudo yum install snapd3.sudo systemctl enable --now snapd.socket4.sudo ln -s /var/lib/snapd/snap /sn

OLDER

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

NEWER

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

Recently Updated

  • nextjs15使用better-sqlite3的连接报错问题
  • nextjs + clerk + supabase + realtime 实时监听数据库更改
  • 解决nextjs15使用useLocalStorage报错的问题
  • mac上使用nodejs appium控制chrome浏览器
  • 2024年终总结

Trending Tags

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

Contents

©2025 sunday. Some rights reserved.

Using the Halo theme Chirpy