GithubHelp home page GithubHelp logo

local-cert-generator's Introduction

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")),
    },
    ....
}

local-cert-generator's People

Contributors

adoussot avatar dakshshah96 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.