本文介绍了无法加载资源:net :: ERR_INSECURE_RESPONSE socket.io的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过ssl连接到服务器上的端口...最近我开始无法加载资源:chrome在连接到node.js + socket.io服务器时在chrome上出现net :: ERR_INSECURE_RESPONSE错误.我的服务器设置代码:

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:

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);

我在做什么错了?

这是我在客户端连接的方式:

This is how i connect on client side:

socket = io.connect("https://website.com:8080", {'reconnect': false});

推荐答案

在使用官方而非自签名证书时,我遇到了类似的问题,而我刚刚找到了解决方案.它仅在Android chrome上失败,顺便说一句.将证书链添加到https.createServer方法的options对象:

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:

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.

这篇关于无法加载资源:net :: ERR_INSECURE_RESPONSE socket.io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 23:36