gpt4 book ai didi

node.js - 具有自签名证书的 https 服务器

转载 作者:太空宇宙 更新时间:2023-11-03 22:51:22 25 4
gpt4 key购买 nike

创建自签名证书后,在 Chrome 中打开不安全的本地主机后:chrome://flags/#allow-insecure-localhost

添加自签名证书系统并“信任所有人”后。下面的代码仍然没有通过 https 托管服务器。chrome 中显示以下错误:

This site can’t provide a secure connection

localhost sent an invalid response.
Try running Network Diagnostics.
ERR_SSL_PROTOCOL_ERROR

我缺少什么才能让它发挥作用?

var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');

// This line is from the Node.js HTTPS documentation.
var options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};

// Create a service (the app object is just a callback).
var app = express();

// Create an HTTP service.
http.createServer(app).listen(8000);
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(8001);

最佳答案

创建证书(遵循http://www.akadia.com/services/ssh_test_certificate.html)并将其添加到钥匙串(keychain)访问对我来说在Mac上有效

    openssl genrsa -des3 -out server.key 1024   
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

关于node.js - 具有自签名证书的 https 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42518513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com