【问题标题】:Rails 5 Error during WebSocket handshake: Unexpected response code: 502WebSocket握手期间的Rails 5错误:意外的响应代码:502
【发布时间】:2020-05-20 04:32:06
【问题描述】:

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

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

我已尝试将 production.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 测试台环境中工作但在使用 ssl 的 https 上给出错误。 我也在使用带有乘客模块的 Nginx 服务器来运行 rails 环境。

【问题讨论】:

    标签: ruby-on-rails ruby nginx ruby-on-rails-5 passenger


    【解决方案1】:

    将 /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;
    }
    

    【讨论】:

    • 这是对您问题的回答还是更新?
    • 这是解决 502 握手错误的答案。
    • 您知道问题的确切原因是什么吗?在这种情况下,请考虑使用原因更新您的答案并将其标记为正确答案。
    猜你喜欢
    • 2017-11-16
    • 2019-11-26
    • 2020-09-19
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 2014-05-02
    • 2020-08-01
    • 1970-01-01
    相关资源
    最近更新 更多