【发布时间】:2017-05-23 15:44:47
【问题描述】:
我已经创建了 Node js 服务器。我的 ubuntu 系统在端口 443 中运行两台服务器 apache,在端口 442 中运行节点 js 服务器。使用 SSL 证书的 Apache 服务器运行良好,但节点 js 显示 SSL 错误。
您的连接不是私密的
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());
});
编辑:
一旦我点击高级并继续不安全的服务器。然后它在浏览器中显示绿色填充。
【问题讨论】:
-
它抱怨权威。我们应该假设它不是自签名证书吗?
-
你的
biz.key和/etc/ssl/biz.crt是从哪里得到的……它们是自签名的吗? -
您应该将选项中的密钥和证书链接到与 apache 使用的资源相同的资源
-
@ÁlvaroGonzález 不,它们是原创的。不是自称从 GoDaddy 购买的。它在 apache 上运行良好。
-
@Pogrindis 不,他们不是自分配的。
标签: javascript node.js ssl