1 Star 1 Fork 0

chuchur / local-cert-generator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

HTTPS for localhost

本地环境生成https证书脚本

1. 克隆库,cd 进入目录

git clone https://github.com/chuchur-china/local-cert-generator.git
cd local-cert-generator

2. 运行脚本以创建根证书:

sh createRootCA.sh

3 . 将刚刚生成的根证书添加到可信证书列表中。此步骤取决于您运行的操作系统:

macOS:打开Keychain Access并将根证书导入您的系统钥匙串。然后将证书标记为受信任。 windows:只需要将根证书添加至信任库即可

keytool -import -v -file D:/根证书路径 -keystore E:\导出信任库路径/xxx.keystore

注意:您可能需要重新启动浏览器才能正确加载新受信任的根证书。

4.运行脚本以创建域证书localhost:

sh createSelfSigned.sh

5. 拷贝server.key和server.crt 到项目对应的目录 在相关配置启用即可

Node中的使用

var path = require('path')
var fs = require('fs')
var express = require('express')
var https = require('https')

var certOptions = {
  key: fs.readFileSync(path.resolve('build/cert/server.key')),
  cert: fs.readFileSync(path.resolve('build/cert/server.crt'))
}

var app = express()

var server = https.createServer(certOptions, app).listen(443)

devServer中的使用

const fs = require('fs')
const path = require('path');

devServer: {
    // http2: true, //这里可以开启http2
    https: {
        key: fs.readFileSync(path.join(__dirname + "/server.key")),
        cert: fs.readFileSync(path.join(__dirname + "/server.crt")),
        ca: fs.readFileSync(path.join(__dirname + "/rootCA.pem")),
    },
    ....
}
MIT License Copyright (c) 2023 chuchur Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

此脚本用来生成本地证书 展开 收起
Shell
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/chuchur/local-cert-generator.git
git@gitee.com:chuchur/local-cert-generator.git
chuchur
local-cert-generator
local-cert-generator
master

搜索帮助