简体   繁体   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');

Dear every one, I tried make https server... and this code. 亲爱的每个人,我都尝试过制作https服务器...和这段代码。 But not working. 但是没有用。

Before i make key.pem, cert.pem for localhost server 在我制作key.pem,localhost服务器的cert.pem之前

Like this code 像这样的代码

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

and this thing in the same folder 和这个东西在同一个文件夹

but not working like this enter image description here 但不能像这样工作在这里输入图片说明

Thank you and Regards.! 谢谢您!!

Your "it's not working" image isn't showing any errors, so it seems to start up just fine. 您的“这不起作用”图像未显示任何错误,因此似乎启动就很好。

However, the code that handles the request isn't actually sending back a response, which would result in requests just "hanging". 但是,处理该请求的代码实际上并没有发送回响应,这将导致请求只是“挂起”。

Instead, try this: 相反,请尝试以下操作:

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