赞
踩
openssl genrsa -des3 -out site.key 2048
这个命令会生成一个私钥。
该私钥使用三重DES加密,以PEM格式保存,可以使用ASCII码解密。
openssl req -new -key site.key -out site.csr
其中:
重命名:mv site.key site.key.org
openssl rsa -in site.key.org -out site.key
openssl x509 -req -days 365 -in site.csr -signkey site.key -out final.crt
https
链接npm i https fs
const fs = require('fs'); const https = require('https'); const priateKey = fs.readFileSync('site.key'); const certificate = fs.readFileSync('final.crt'); const options = { key: priateKey, cert: certificate, }; https.createServer(options, (req, res) => { res.writeHead(200); res.end("Hello World!"); }).listen(443, '0.0.0.0', () => { console.log('https://0.0.0.0:443/') })
http
自动跳转到https
const fs = require('fs'); const https = require('https'); const http = require('http'); const priateKey = fs.readFileSync('site.key'); const certificate = fs.readFileSync('final.crt'); const options = { key: priateKey, cert: certificate, rejectUnauthorized: false, }; https.createServer(options, (req, res) => { res.writeHead(200); res.end("Hello World!"); }).listen(443, '0.0.0.0', () => { console.log('https://0.0.0.0:443/') }) http.createServer((req, res) => { console.log(req.url); if(req.url === '/') res.writeHead(301, { 'Location': 'https://0.0.0.:443' }); res.end("hi"); }).listen(80, '0.0.0.0', () =>{ console.log('http://0.0.0.0:80/') });
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。