Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 连接到nodejs https服务器时重置连接_Node.js_Ssl_Https_Server - Fatal编程技术网

Node.js 连接到nodejs https服务器时重置连接

Node.js 连接到nodejs https服务器时重置连接,node.js,ssl,https,server,Node.js,Ssl,Https,Server,所以我试图在节点中运行一个基本的https服务器,我完全被卡住了。我已经用openssl生成了一个自签名证书和密钥,并尝试了创建服务器和另外一百个证书和密钥的基本方法,但无论我做什么,当我尝试连接时,我的浏览器只是告诉我“连接已重设”,而服务器甚至没有为请求执行回调函数,就好像它从未到达一样 Firefox开发者版中的network inspector显示服务器没有任何响应,使用Wireshark检查我的环回接口时,我发现服务器在确认浏览器请求后立即发送“end”包 我真的不知道什么是错误的,因

所以我试图在节点中运行一个基本的https服务器,我完全被卡住了。我已经用openssl生成了一个自签名证书和密钥,并尝试了创建服务器和另外一百个证书和密钥的基本方法,但无论我做什么,当我尝试连接时,我的浏览器只是告诉我“连接已重设”,而服务器甚至没有为请求执行回调函数,就好像它从未到达一样

Firefox开发者版中的network inspector显示服务器没有任何响应,使用Wireshark检查我的环回接口时,我发现服务器在确认浏览器请求后立即发送“end”包

我真的不知道什么是错误的,因为我尝试了许多教程中的示例代码,所有这些代码都产生相同的输出

这是一些基本代码的示例,这些代码不会抛出错误,但显然也不起作用:

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

const options = {
    key: fs.readFileSync('sslcert/key.pem'),
    cert: fs.readFileSync('sslcert/server.crt'),
    rejectUnauthorized: false
}
https.createServer(options, (req, res) => {
    console.log('request received')
    res.writeHead(200)
    res.end('hello')
}).listen(8443).on('error', (error) => {
    throw error
})

我也有同样的问题,对我来说,使用指定的https://-协议访问页面在Firefox中完成了这项工作

所以使用 而不仅仅是

这是正确的!如果你7个月前还在这里:在24小时的搜索和尝试不同的解决方案后,我收到了PSAVE!还可以查看以了解如何在Node.js中创建简单的HTTP到HTTPS重定向