WebSocket 握手期间出现 Rails 5 错误:意外响应代码:502



我在我的rails应用程序中使用web-socket: 使用 Rails 5.2.3,ruby 2.4.0p0,我的 websocket 可以通过 http 查找,但在切换到 https 时出现以下错误。 错误如下:

与"wss://tukaweb.com/cable"的 WebSocket 连接失败:期间出错 WebSocket 握手:意外响应代码:502

我尝试将生产.rb 中的配置更改为

config.action_cable.url = 'wss://tukaweb.com/cable'
config.action_cable.allowed_request_origins = [ 'http://tukaweb.com', /http://tukaweb.*/ ]

config.action_cable.url = [/ws://*/, /wss://*/]
config.action_cable.allowed_request_origins = [/http://*/, /https://*/]

还添加了动作电缆元标记:

<%= action_cable_meta_tag %>

但是错误仍然存在,任何人都可以建议正确的配置,谢谢,以及为什么它在 http 测试台环境中工作查找,但在带有 ssls 的 https 上给出错误。 我也在使用带有乘客模块的 Nginx 服务器来运行轨道环境。

将/home/vidur/Downloads/tukaweb/app/assets/javascripts/cable.js 更新为:

//= require action_cable
//= require_self
//= require_tree ./channels
(function() {
this.App || (this.App = {});
App.cable =  ActionCable.createConsumer("/cable");
}).call(this);

Production.rb 到:

config.action_cable.url = "/cable"
config.action_cable.allowed_request_origins = [ 'http://52.35.24.20','http://tukaweb.com', 'https://tukaweb.com' ]

routes.rb 到:

mount ActionCable.server => '/cable'

cable.yml 到:

development:
adapter: redis
url: redis://localhost:6379/1
test:
adapter: async
production:
adapter: redis
url: redis://localhost:6379/1

将虚拟主机更新为:

location /cable {
passenger_app_group_name tukaweb_action_cable;
passenger_force_max_concurrent_requests_per_process 0;
}

最新更新