我已经创建了 Node js 服务器。我的 ubuntu 系统在端口 443 中运行两台服务器 apache,在端口 442 中运行 Node js 服务器。Apache 服务器使用 SSL 证书运行良好,但 Node js 显示 SSL 错误。
您的连接不是私有(private)的
server.js:
var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');
var inbox=require('./functions.js');
var app = express();
// This line is from the Node.js HTTPS documentation.
var options = {
key: fs.readFileSync('/etc/ssl/biz.key'),
cert: fs.readFileSync('/etc/ssl/biz.crt')
};
// Create a service (the app object is just a callback).
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
// Create an HTTP service.
http.createServer(app).listen(81);
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(442,function () {
console.log('Server Time'+new Date().Now());
});
编辑:
一旦我点击高级并继续不安全的服务器。然后它正在浏览器中显示绿色填充。
最佳答案
您的 Node https 配置未发送中间证书。使用 ca
选项为客户端发送这些,以便能够形成完整的链。
var options = {
key: fs.readFileSync('/etc/ssl/biz.key'),
cert: fs.readFileSync('/etc/ssl/biz.crt'),
ca: <insert your ca bundle here>
};
如果您从 Apache(通过端口 443)提供服务的站点也在您的移动浏览器中显示此警告,则您必须在 Apache 中执行类似的操作。您可以使用 SSL Labs测试您网站的证书和其他 TLS 设置。
关于javascript - 您的连接不是 Node js 中的私有(private)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44139467/