【问题标题】:Rails 5 - Error during WebSocket handshake: 'Connection' header value must contain 'Upgrade'Rails 5 - WebSocket 握手期间出错:“连接”标头值必须包含“升级”
【发布时间】:2016-05-21 02:23:12
【问题描述】:

我目前正在尝试使用 Rails 5.0.0.beta2 部署应用程序,但是当我在我的 javascript 控制台中加载应用程序时,我看到了

与“wss://example.com/cable”的 WebSocket 连接失败:WebSocket 握手期间出错:“Connection”标头值必须包含“Upgrade”

我使用 Apache/Passenger 作为 Web 服务器。

有其他人遇到过这个问题吗?如果有,您是如何解决的?

【问题讨论】:

  • 你解决了吗?
  • 我已经解决了这个问题。实际上有 3 个步骤可以做到这一点:A) 使用 wss://example.com/cable 2) 更改端口(从 80 更改为其他端口)3) 在防火墙例外中添加您的 ip。跨度>

标签: ruby-on-rails ruby websocket ruby-on-rails-5 actioncable


【解决方案1】:

网络服务器将需要升级 websocket 连接,以便连接能够持续。我猜你看到的 jscript 错误不会发生这种情况。

如果您使用的是 Nginx,这里是使用 Nginx 反向代理配置的方法:ActionCable on AWS: Error during WebSocket handshake: Unexpected response code: 404

这是关键部分:

      # enables WS support
      location /cable {
        proxy_pass http://backend;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
      }

还可以考虑使用 puma 代替乘客。

【讨论】:

  • 我已经改了。但仍然没有运气:(这是我的配置文件:location /cable { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; passenger_app_group_name gorails_websocket; passenger_force_max_concurrent_requests_per_process 0; }
  • 是否可以在 apache 服务器上使用 websockets 和乘客(使用 nodejs,而不是 ruby​​)??
猜你喜欢
  • 2019-05-16
  • 1970-01-01
  • 1970-01-01
  • 2014-04-25
  • 2017-05-09
  • 2015-06-17
  • 1970-01-01
  • 1970-01-01
  • 2020-08-17
相关资源
最近更新 更多