繁体   English   中英

Nginx反向代理找不到Node.js socket.io GET 404

[英]Node.js socket.io cannot GET 404 not found with Nginx reverse proxy

因此,我试图在nodejs / socket.io中制作游戏,但是每当我将其部署在具有反向代理的服务器上均无法正常工作时,一切都在本地正常运行,但在反向代理上会出现404 not found错误。

应用端口为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 /;
 }

当我转到myIpAdress / node /时,我得到了index.html文件,并且可以登录到应用程序,以便socket.io可以正常工作,但无效的是外部文件'myIpAdress / node / client / img的链接/player.png'会显示404错误。

任何想法到客户端文件夹的路径是什么?

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

location /client {
    alias /path/to/client;
    access_log off;
}

上面的位置块告诉NGINX通过从本地/ path / to / client目录提供内容来响应客户对yourdomain.com/client/中内容的请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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