简体   繁体   English

无法使用代理与Node.js连接

[英]Unable to connect with nodejs using proxy

I am using node.js for my chat application with https. 我正在使用https将node.js用于我的聊天应用程序。 It is working fine in all condition but the problem is with VPN. 在所有情况下都可以正常工作,但问题出在VPN上。

I installed the turbo VPN into my android phone and connected to the proxy server. 我将Turbo VPN安装到我的android手机中,并连接到代理服务器。 After this whenever I am going to connect to the chat server it fails every time and shows an error 之后,每当我要连接到聊天服务器时,它每次都会失败并显示错误

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

Here is the requested headers 这是请求的标题

Provisional headers are shown 显示临时标题

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

Here is my server.js code 这是我的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);

Looking at your header you are connecting to your site with HTTPS but I don't see you inserting your certificate in the variable opts. 查看您的标头,您正在使用HTTPS连接到您的站点,但是我看不到您将证书插入变量opts中。

Shot in the wild but try this 在野外射击,请尝试一下

Add your certificate privkey and cert to the folder you keep your server.js file in 将证书privkey和cert添加到保存server.js文件的文件夹中

Server side: 服务器端:

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

Client side: 客户端:

<script>
  var socket = io.connect('https://yourwebsite.com:8080', { secure:true });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM