简体   繁体   中英

Node.js socket.io/?EIO=3&transport=polling&t=LcuVjT6 404 (Not Found) reverse proxy

I am trying to deploy a nodeJs application on a server.

I get 404 on urls like this: socket.io/?EIO=3&transport=polling&t=LcuVjT6 404 (Not Found) and also socket.io/?EIO=3&transport=polling&t=LcuVcaN Failed to load resource: the server responded with a status of 404 (Not Found).

my dir structure:

    ├── app.js
├── client
│   ├── css
│   │   └── main.css
│   ├── fonts
│   ├── img
│   ├── index.html
│   ├── index.pug
│   └── js
│       └── main.js
├── package.json

app.js

var express = require('express');
var app = express();
var serv = require('http').Server(app);

app.get('/',function(req, res){
  res.sendFile(__dirname + '/client/index.html');
});

app.use('/client',express.static(__dirname + '/client'));

serv.listen(8080);

var io = require('socket.io')(serv,{});

io.sockets.on('connection',function(socket){ //code }

index.pug

  ...
  script(src='https://cdn.socket.io/socket.io-1.4.5.js')
  script.
    var socket = io();
  ...

I've tried to change port to 8080 but doesn't help, The only thing that displays on servername:8080 is the html and css part. It look like the client can't load the socket.io js file, I have tried to set the script at the beginning of my pug file but no luck.

edit: My server is at my home, when I browse to 192.168.1.2:8080 it works as it should. I have a reverse proxy from 127.0.0.1:8080 to mywebsite.com/sevaho/nodegame/ so this is where it goes wrong.

nginx.conf

#REVERSE-PROXY APP 8080
     location ~ /sevaho/nodegame.* {
     rewrite (/nodegame)$ / break;
     rewrite /nodegame/(.*) /$1 break;
     proxy_pass http://127.0.0.1:8080;
     proxy_redirect / /nodegame/;
     proxy_set_header Host $host;
     proxy_set_header Origin http://$host; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection $http_connection;
     }

Anyone able to see the problem?

It's maybe outdatet, but you should make sure the port is free and open. This was my problem with basic tutorials where the port was changed form 80 (which is open and ready) to 8080, 4000 and other possibilities. Without opening the port you use you could everytime run into this problem. So check this first before you change the code while someone forget you have to open the port and means the code cannot work so far. In this question of mine ill test all the possibilities with the tutorials i found and at this time all of them work perfectly fine. Just because of opening the right port. Node js and Socket.io Problems

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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