我正在使用node.js和我的聊天应用程序使用https。它在所有条件下都能正常工作,但问题在于VPN。
我将turbo VPN安装到我的Android手机中并连接到代理服务器。在此之后,每当我要连接到聊天服务器时,它每次都会失败并显示错误
socket.io.min.js?v=1498289112:2
GET https://www.xxxxx.com:30002/socket.io/?u=5&pathname=%2Fdashboard&EIO=3&transport=polling&t=Lx7Tlf8 net::ERR_CONNECTION_TIMED_OUT
以下是请求的标题
显示临时标题
Origin:https://www.xxxx.com
Referer:https://www.xxxxx.com/dashboard
User-Agent:Mozilla/5.0 (Linux; Android 6.0.1; MotoG3 Build/MPIS24.107-55-2-17) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Mobile Safari/537.36
这是我的server.js代码
var socket = require("socket.io");
var express = require("express");
var http = require('https');
var fs = require("fs");
var app = express();
var opts = {
key : fs.readFileSync("/home/myhomedir/ssl/keys/9ca41_e1cd7_ece6805e7bdddf1ec6859d5cb27ab30f.key"),
cert : fs.readFileSync("/home/myhomedir/ssl/certs/xxxx_9ca41_e1cd7_1529438222_b65b92c90fc0973371157d99ea679f4f.crt"),
ca : [fs.readFileSync("gd.crt"), fs.readFileSync("g1.crt"), fs.readFileSync("g2.crt")],
requestCert : true,
rejectUnauthorized : false
};
var server = http.createServer(opts, app);
app.set('trust proxy', true);
var server = http.createServer(app);
var io = socket.listen(server);
答案 0 :(得分:0)
查看您的标题,您使用HTTPS连接到您的网站,但我没有看到您将证书插入变量opts。
在野外拍摄,但试试这个
将证书privkey和cert添加到
中保存server.js文件的文件夹中服务器端:
var fs = require('fs');
var options = {
key: fs.readFileSync('privkey.pem'),
cert: fs.readFileSync('cert.pem')
};
var app = require('express')();
var http = require('https').Server(options, app);
var io = require('socket.io')(http);
var port = 8080;
http.listen(port, function(){
console.log('listening on *:' + port);
});
客户方:
<script>
var socket = io.connect('https://yourwebsite.com:8080', { secure:true });
</script>