Giter Club home page Giter Club logo

vue-async's Introduction

Nodejs创建https服务器(Windows 10/7)

搭建https步骤:

    1. 生成 OpenSSL证书
    1. 使用Nodejs的https模块建立服务器

OpenSSL证书(需要安装git或者Cygwin等含有linux环境工具)(以下操作都是在项目根目录下)

    1. 生成私钥key文件
openssl genrsa -out privatekey.pem 1024
    1. 通过私钥生成CSR证书签名
openssl req -new -key privatekey.pem -out certrequest.csr
    1. 通过私钥和证书签名生成证书文件
openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certification.pem

Nodejs https 服务器示例

const https = require('https')
const fs = require('fs')
const path = require('path')
const resolve = (dir) => path.join(__dirname, '..' , dir)
const options = {
  key: fs.readFileSync('privatekey.pem'),
  cert: fs.readFileSync('certification.pem'),
  //ca: fs.readFileSync('./SSL/root_bundle.crt')    //这个线上环境需要
}

const app = https.createServer(options, (req, res) => {
  res.writeHead(200)
  res.end('hello world\n')
})

app.listen('8001', '0.0.0.0', () => {
  console.log('HTTPS Server running at https://0.0.0.0');
})

在浏览器中输入: https://localhost:8001

注意:

node>=9.0, http2服务无法使用...

参考地址:

  1. Nodejs创建https服务器(Windows 7)

vue-async's People

Contributors

flowerinsunnysun avatar ly2011 avatar

Watchers

win avatar  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.