[英]Node.js + Apache - https://localhost:3000/socket.io/ ERR_CONNECTION_REFUSED
I am implementing a simple game in Node.js. 我正在Node.js中实现一个简单的游戏。 I have a
client.js
for my client side code, and a server.js
running on a remote server, which both use sockets to communicate on port 3000 我有一个用于客户端代码的
client.js
,以及一个在远程服务器上运行的server.js
,它们都使用套接字在端口3000上进行通信
I am also running Apache on port 80 , and using ProxyPass
in my apache configuration file, to route the url mywebsite.io/agario
to my nodejs server. 我还在端口80上运行Apache,并在apache配置文件中使用
ProxyPass
将URL mywebsite.io/agario
路由到我的nodejs服务器。
<Location /agario>
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
I am also using cloudflare to route my webserver 167.179.xx.xx through the url https://agario.mywebsite.io
for SSL so that I can use HTTPS. 我还使用cloudflare通过SSL的URL
https://agario.mywebsite.io
路由我的Web服务器167.179.xx.xx,以便可以使用HTTPS。
The problem 问题
When I try to connect to my website https://agario.mywebsite.io/agario I am receiving the following error: 当我尝试连接到我的网站https://agario.mywebsite.io/agario时,出现以下错误:
socket.io-1.4.5.js:1 GET https://localhost:3000/socket.io/?EIO=3&transport=polling&t=MakAMgZ net::ERR_CONNECTION_REFUSED
I am unclear why my client code is trying to connect to localhost, when I have specified in the code to connect to the remote server. 当我在代码中指定要连接到远程服务器时,我不清楚为什么我的客户端代码尝试连接到本地主机。 Potentially I am just confused on how to run the node.js server as this is my first taste of Node.js and sockets.
潜在地,我只是对如何运行node.js服务器感到困惑,因为这是我对Node.js和套接字的第一次尝试。
client.js client.js
...
var socket;
socket = io.connect('https://agario.mywebsite.io/agario');
...
server.js server.js
var app = express();
var server = app.listen(3000, listen);
// This call back just tells us that the server has started
function listen() {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://' + host + ':' + port);
}
app.use(express.static('public'));
var io = require('socket.io')(server);
io.sockets.on('connection',
function(socket) {
console.log("We have a new client: " + socket.id);
...
});
If I have missed out any vital information please let me know and I will update my question, thank you. 如果我错过了任何重要信息,请告诉我,我会更新我的问题,谢谢。
You server is listening on port 3000 and you're trying to connect with it via 443, you should try something like this 您的服务器正在侦听端口3000,并且您正在尝试通过443与之连接,您应该尝试执行以下操作
socket.connect('https://ip:3000');
However, if you're sure that ur client is using the same port as the server or u have a port forwarding then try to use netcat
just to make sure the the problem is with your script not the network config : 但是,如果您确定您的客户端使用的是与服务器相同的端口,或者您使用的是端口转发,则尝试使用
netcat
只是为了确保问题出在脚本而不是网络配置上:
nc -zv -w1 ip port
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.