node.js - https ssl/tls 无法在 Nodejs 中的 localhost 上工作

标签 node.js ssl express

https 模块无法在我的本地主机上工作。我已经经历过这个blog.mgechev.com教程。我的 Node v5.10.1。

这里的代码:

//index.js
var fs = require('fs'),
https = require('https'),
express = require('express'),
app = express();

https.createServer({
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
}, app).listen(55555);

app.get('/', function (req, res) {
  res.header('Content-type', 'text/html');
  return res.end('<h1>Hello, Secure World!</h1>');
});

node index.js

输出:

enter image description here

最佳答案

这是一个愚蠢的错误。我只是用前面的 https 点击 url,它工作正常。

即:-

https://localhost:55555

关于node.js - https ssl/tls 无法在 Nodejs 中的 localhost 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36497425/

相关文章:

ios - AFNetworking - SSL - 添加了 .cer 文件,但服务器端出现 400 错误

java - 为什么 Post 方法不在 HTTPS/SSL 上的 Tomcat7 中加密 header

javascript - 带有 node.js 和 express 的基本网络服务器,用于提供 html 文件和 Assets

php - 如何在node.js中全局声明数据库连接

node.js - 如何在nodejs中使用superagent语法更改值属性?

node.js - 在nodejs中使用axios下载图片

windows - 在 Windows 上安装 Node 包时出现 ETIMEDOUT 错误

ssl - MariaDB 启用 TLS 但仍然允许没有 TLS 的连接

node.js - 为什么 Express 不是中间件?

node.js - 在多个 NPM 包之间共享一个 Mongoose 实例