部署到VPS服务器时express-ws不处理呼叫 [英] express-ws doesn't handle call when deployed to VPS server

查看:145
本文介绍了部署到VPS服务器时express-ws不处理呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用node.js + express编写的后端,并且具有express-ws依赖.

在本地,一切正常.以前它被部署到红帽开放式转变,也没有任何问题.昨天我购买了VPS,对其进行了配置并部署到了那里.除了websockets,其他所有东西都可以正常工作.

我有启用了SSL的nginx,该ng中的下一行与服务器相关

server {
  listen       ipaddresshere:80 default;
  server_name  _;

  location / {
      proxy_pass  http://ipaddresshere:8080;
  }

  location /ws {
      proxy_pass  http://ipaddresshere:8080;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

  }
}

我还有其他配置位置,但是它们是由VestaCP和 https://certbot.eff.org/生成的a>

我知道对/ws路由的请求即将到达node.js应用程序(我正在记录它).但这并没有交给那个处理程序

app.ws('/ws', SocketsHandler.registerWs);

最后,它与我的上一个处理程序匹配并返回404

app.get('*', ErrorHandler.notFound);

问题:WS库在VPS环境中不起作用,但我在控制台中看不到任何错误是什么呢??

P.S.我在本地运行没有SSL和Nginx的应用程序

wsServer.on('connection', function (socket) {...})

解决方案

我发现我的配置被其他文件覆盖.因此,而不是连接升级";服务器正在接收连接关闭".

I have back-end written using node.js + express with express-ws depedency.

Locally everything works like it should. Previously it was deployed to red hat open shift, also haven't had any problem. Yesterday I bought VPS configured it and deployed there. Everything works except websockets.

I have nginx with enabled SSL that has the next lines in config related to the server

server {
  listen       ipaddresshere:80 default;
  server_name  _;

  location / {
      proxy_pass  http://ipaddresshere:8080;
  }

  location /ws {
      proxy_pass  http://ipaddresshere:8080;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

  }
}

I have other config places but they were generated by VestaCP and https://certbot.eff.org/

What I know that request to /ws route is coming to node.js app (I am logging it). But it doesn't go to that handler

app.ws('/ws', SocketsHandler.registerWs);

In the end it matches with my last handler and returns 404

app.get('*', ErrorHandler.notFound);

The question: What it can be that WS library doesn't work in VPS environment but I don't see any error in console... ?

P.S. Localy I run app without SSL and nginx

wsServer.on('connection', function (socket) {...})

解决方案

I found that my config was overridden by some other file. So instead of Connection "upgrade"; server was receiving Connection "close"..

这篇关于部署到VPS服务器时express-ws不处理呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆