Node.js socket.io/?EIO=3&transport=polling&t=LcuVjT6 404(未找到)反向代理



我正在尝试在服务器上部署nodeJs应用程序。

我在这样的网址上得到 404:socket.io/?EIO=3&transport=polling&t=LcuVjT6 404(未找到),还有 socket.io/?EIO=3&transport=polling&t=LcuVcaN 无法加载资源:服务器以状态 404(未找到)响应。

我的目录结构:

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

应用.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 }

索引.哈巴狗

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

我试图将端口更改为 8080 但没有帮助,服务器名称:8080 上显示的唯一内容是 html 和 css 部分。看起来客户端无法加载 socket.io js 文件,我试图在我的 pug 文件的开头设置脚本,但没有运气。

编辑:我的服务器在我家,当我浏览到192.168.1.2:8080时,它正常工作。我有一个从 127.0.0.1:8080 到 mywebsite.com/sevaho/nodegame/的反向代理,所以这就是出错的地方。

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

有人能够看到问题吗?

它可能已经过时了,但您应该确保端口是免费且开放的。这是我在基本教程中的问题,其中端口从 80(已打开并准备就绪)更改为 8080、4000 和其他可能性。如果不打开您使用的端口,您每次都可能遇到此问题。因此,在更改代码之前先检查一下,因为有人忘记了您必须打开端口,这意味着代码到目前为止无法正常工作。在我的这个问题中,用我找到的教程测试所有可能性,此时它们都运行良好。只是因为打开了正确的端口。节点 js 和 Socket.io 问题