Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js socket.io无法使用Nginx反向代理获取404未找到_Node.js_Nginx_Socket.io_Reverse Proxy - Fatal编程技术网

Node.js socket.io无法使用Nginx反向代理获取404未找到

Node.js socket.io无法使用Nginx反向代理获取404未找到,node.js,nginx,socket.io,reverse-proxy,Node.js,Nginx,Socket.io,Reverse Proxy,因此,我试图在nodejs/socket.io中制作一个游戏,但每当我在带有反向代理的服务器上部署它时,它都不起作用,在本地一切正常,但在反向代理上,它会给出404个未找到的错误 应用端口为5000 目录结构: ├── app.js ├── client │ ├── css │ │ └── main.css │ ├── fonts │ ├── img │ ├── index.html │ ├── index.pug │ └── js │ └── mai

因此,我试图在nodejs/socket.io中制作一个游戏,但每当我在带有反向代理的服务器上部署它时,它都不起作用,在本地一切正常,但在反向代理上,它会给出404个未找到的错误

应用端口为5000

目录结构:

├── 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('/node',function(req, res){
  res.sendFile(__dirname + '/client/index.html');
});
app.use('/client',express.static(__dirname + '/client'));
serv.listen(5000);
var SOCKET_LIST={};
var io = require('socket.io')(serv,{});
index.html:

var socket = io();
Img.player.src='client/img/player.png'; //I have more like this
Nginx:

 location ~ ^/(node|socket\.io) {
 proxy_pass http://127.0.0.1:5000;
 proxy_set_header Host $host;
 proxy_set_header Origin http://$host; 
 proxy_http_version 1.1;
 proxy_cache_bypass $http_upgrade;
 proxy_set_header Upgrade $http_upgrade;
 proxy_set_header Connection $http_connection;
 sub_filter /node /;
 }
当我转到myipAddress/node/时,我得到index.html文件,我可以登录到应用程序以便socket.io工作,但不工作的是指向外部文件“myipAddress/node/client/img/player.png”的链接给出404错误


知道客户端文件夹的路径吗?

尝试添加另一个位置块,如下所示:

location /client {
    alias /path/to/client;
    access_log off;
}
上面的位置块告诉NGINX通过从local/path/to/client目录提供内容来响应客户端对yourdomain.com/client/中内容的请求