找不到404 Nginx-具有反向代理的Socket.io

时间:2019-12-20 11:50:11

标签: node.js nginx socket.io

这篇文章显然是重复的,但这不是因为我已经尝试过对类似问题的所有答复。

我的节点服务器中有类似的东西

var app = express();
var server = app.listen(3000);
var io = require('socket.io')(server);

在React中我也有这个:

import io from 'socket.io-client'
const socket = io.connect('https://myurl.com/',{
  reconnection: true,
  reconnectionDelay: 1500,
  reconnectionAttempts: 10
})
export default socket

最后在nginx中我有这个:

server_name _;

location ~ ^/(api|socket\.io) {
  proxy_pass http://IPHERE:60000;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection 'upgrade';
  proxy_set_header Host $host;
  proxy_cache_bypass $http_upgrade;
  # First attempt to serve request as file, then
  # as directory, then fall back to displaying a 404.
  #try_files $uri $uri/ =404;
}

location / {
  try_files $uri /index.html;
}

这适用于/api个请愿书。另外,如果我在https://myurl.com/socket.io/asd上进行请愿,也会返回以下答复:

code    0
message "Transport unknown"`

因此,代理正在工作。

问题是当我使用套接字参数进行请愿时: https://myurl.com/socket.io/?EIO=3&transport=polling&t=MyZ6Vzr返回了我: 404 Not Found nginx

怎么了?

0 个答案:

没有答案