简体   繁体   English

Node.js + Apache-https:// localhost:3000 / socket.io / ERR_CONNECTION_REFUSED

[英]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.

相关问题 ERR_CONNECTION_REFUSED http://localhost:3000/socket.io/socket.io.js - ERR_CONNECTION_REFUSED http://localhost:3000/socket.io/socket.io.js Heroku Node.js + Socket.io:部署到Heroku后,我得到一个ERR_CONNECTION_REFUSED - Heroku Node.js + Socket.io: After deploying to Heroku, I get a ERR_CONNECTION_REFUSED Node.js服务器上带有socket.io的ERR_CONNECTION_REFUSED - ERR_CONNECTION_REFUSED with socket.io on Node.js server Socket.IO ERR_CONNECTION_REFUSED - Socket.IO ERR_CONNECTION_REFUSED polling-xhr.js:229 GET http://localhost:3000/socket.io/?EIO=4&transport=polling&t=NMtL4rR.net::ERR_CONNECTION_REFUSED - polling-xhr.js:229 GET http://localhost:3000/socket.io/?EIO=4&transport=polling&t=NMtL4rR net::ERR_CONNECTION_REFUSED 我正在获取GET http:// localhost:81 / socket.io / socket.io.js net :: ERR_CONNECTION_REFUSED - I am getting GET http://localhost:81/socket.io/socket.io.js net::ERR_CONNECTION_REFUSED 在3000端口上带有https的Node.js socket.io - Node.js socket.io with https on 3000 port 加载反应应用程序错误时,polling-xhr.js:203 GET https://localhost:8001/socket.io/?EIO=4&amp;transport=polling&amp;t=NZJdzB8 net::ERR_CONNECTION_REFUSED - while loading react app error , polling-xhr.js:203 GET https://localhost:8001/socket.io/?EIO=4&transport=polling&t=NZJdzB8 net::ERR_CONNECTION_REFUSED node.js / jQuery跨域:ERR_CONNECTION_REFUSED - node.js / jQuery cross domain: ERR_CONNECTION_REFUSED localhost(和socket.io)上的Node.js - Node.js on localhost (and socket.io)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM