node.js 无法加载资源:net::ERR_INSECURE_RESPONSE socket.io
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24504827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to load resource: net::ERR_INSECURE_RESPONSE socket.io
提问by user3455531
I am connecting to a port on my server via ssl... recently i have started to get Failed to load resource: net::ERR_INSECURE_RESPONSE error on chrome while connecting to the node.js+socket.io server.Here is my server setting up code:
我正在通过 ssl 连接到我服务器上的一个端口......最近我开始在连接到 node.js+socket.io 服务器时出现无法加载资源:net::ERR_INSECURE_RESPONSE 错误。这是我的服务器设置上代码:
var fs = require('fs');
var express = require('express');
var routes = require('./routes');
var https = require('https');
var path = require('path');
var socketio = require('socket.io');
var util = require('util');
var url = require('url');
var privateKey = fs.readFileSync('ssl/keys/xxxxxxxxxxxxxxxxxxxxxxxx.key', 'utf8');
var certificate = fs.readFileSync('ssl/certs/xxxxxxxxxxxxxx.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var sizeOf = require('image-size');
var DBWrapper = require('node-dbi').DBWrapper;
var DBExpr = require('node-dbi').DBExpr;
var dbConnectionConfig = { host: 'localhost', user: 'user', password: 'password', database: 'dbname' };
dbWrapper = new DBWrapper( "pg", dbConnectionConfig );
dbWrapper.connect();
var app = express();
app.set('port', process.env.PORT || 8080);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', routes.index);
var server = https.createServer(credentials,app).listen(app.get('port'), function(){
console.log("Express server listening on port with https " + app.get('port'));
});
var io = socketio.listen(server);
What am i doing wrong?
我究竟做错了什么?
Edit: This is how i connect on client side:
编辑:这是我在客户端连接的方式:
socket = io.connect("https://website.com:8080", {'reconnect': false});
采纳答案by KLoozen
I had a similar issue when using an offical, not self signed certificate and I just found the solution. It only failed in chrome on Android, btw. Add the certifate chain to the options object of the https.createServer method:
我在使用官方而非自签名证书时遇到了类似的问题,我刚刚找到了解决方案。顺便说一句,它仅在 Android 上的 chrome 中失败了。将证书链添加到 https.createServer 方法的选项对象:
var hskey = fs.readFileSync('/the_key.key');
var hscert = fs.readFileSync('/the_cert.pem')
var ca = fs.readFileSync('/The_CA_bundle.pem')
var credentials = {
ca:ca,
key: hskey,
cert: hscert
};
var server = https.createServer(credentials,app).listen(app.get('port'), function(){
console.log("Express server listening on port with https " + app.get('port'));
});
Just putting it here, to prevent someone else banging his head against the wall when having a similar issue.
只是把它放在这里,以防止其他人在遇到类似问题时用头撞墙。
回答by Rémi Becheras
Your certificate is probably self-signed.
您的证书可能是自签名的。
Chromium block this kind of insecure content.
If you are alone to use it as testing for example, you can just unblock it opening a new tab in Google chrome and going to https://example.com:8080. Chrome will advertise you that the resource use a self-signed SSL certificate and ask you if you want to continue. If you do, your app will now work on your first tab.
Chromium 会阻止这种不安全的内容。例如,如果您单独使用它作为测试,您可以取消阻止它在谷歌浏览器中打开一个新标签并转到https://example.com:8080. Chrome 会通知您该资源使用自签名 SSL 证书,并询问您是否要继续。如果您这样做,您的应用程序现在将在您的第一个选项卡上运行。
Remember that you will do it for each navigation session in chrome.
请记住,您将在 chrome 中为每个导航会话执行此操作。
回答by Viliam Kocinsky
Thanks. That solved also my problem. In my case I was running front-end Angular 2 in development mode on localhost:3000 and back-end on https://server:8443and I was also getting
谢谢。这也解决了我的问题。就我而言,我在 localhost:3000 上以开发模式运行前端 Angular 2,在https://server:8443上运行后端,我也得到了
net::ERR_INSECURE_RESPONSE
My solution was to navigate to https://server:443which was running deployed front-end and confirm self-signed certificate.
我的解决方案是导航到运行部署的前端的https://server:443并确认自签名证书。
回答by Jun Bin
I had a recent problem with this error and all I did was change the endpoints to HTTP instead of https but that could also be depending on your implementation.
我最近遇到了这个错误的问题,我所做的只是将端点更改为 HTTP 而不是 https 但这也可能取决于您的实现。

