[英]Create an HTTPS server with Node.js
I'm getting error while trying to access HTTPS server I created with NodeJS. 尝试访问用NodeJS创建的HTTPS服务器时出现错误。
What do I do : 我该怎么办 :
1.First of all : generate a self-signed certificate : 1.首先: 生成一个自签名证书 :
openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
2.Create simple NodeJs Https server - 2.创建简单的NodeJs Https服务器-
var https = require('https');
var fs = require('fs');
var server_port = 8080;
var httpsOptions = {
key: fs.readFileSync('\key.pem'),
cert: fs.readFileSync('\cert.pem')
};
var app = function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}
https.createServer(httpsOptions, app).listen(server_port);
run the server : node main.js (the file name) The server is running but when I try access https://localhost:8080 运行服务器:node main.js(文件名)服务器正在运行,但是当我尝试访问https:// localhost:8080时
Connect to the server. 连接到服务器。 The result is: 结果是:
Probably this port used by another application (eg skype). 此端口可能已被其他应用程序(例如,Skype)使用。 Try another port. 尝试其他端口。
try with: 尝试:
openssl genrsa -out key.pem 1024
or 要么
openssl genrsa -out key.pem 2048
A key size of 512 is considered weak 密钥大小512被认为是弱的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.