繁体   English   中英

node.js localhost https服务器无法正常工作

[英]node.js localhost https server not working anything

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

const options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};

https.createServer(options,(req,res)=>{

  console.log('https server start');
}).listen(8080,'localhost');

亲爱的每个人,我都尝试过制作https服务器...和这段代码。 但是没有用。

在我制作key.pem,localhost服务器的cert.pem之前

像这样的代码

openssl genrsa 1024 > key.pem
openssl req -x509 -new -key key.pem > cert.pem

和这个东西在同一个文件夹

但不能像这样工作在这里输入图片说明

谢谢您!!

您的“这不起作用”图像未显示任何错误,因此似乎启动就很好。

但是,处理该请求的代码实际上并没有发送回响应,这将导致请求只是“挂起”。

相反,请尝试以下操作:

https.createServer(options, (req, res) => {
  res.end('Hello, world!');
}).listen(8080, 'localhost', () => {
  console.log('https server start');
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM