代码之家  ›  专栏  ›  技术社区  ›  Ryzal Yusoff

ActionCable Rails 5(乘客)-失败:WebSocket握手期间出错:意外响应代码:404

  •  6
  • Ryzal Yusoff  · 技术社区  · 6 年前

    https://gorails.com/episodes/deploy-actioncable-and-rails-5

    该应用程序是使用Phusion Passenger+Nginx+Capistrano部署的。

    WebSocket connection to 'ws://139.59.175.34/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

    以下是我的设置:

    /etc/nginx/sites enabled/默认值

    server {
            listen 80;
            listen [::]:80 ipv6only=on;
    
            server_name my_server_domain;
            passenger_enabled on;
            rails_env    production;
            root         /home/deploy/my_app_domain/current/public;
    
            # ActionCabel config (disable this if u r not using it)
            location /cable {
               passenger_app_group_name actioncable_websocket;
               passenger_force_max_concurrent_requests_per_process 0;
            }
    
            # redirect server error pages to the static page /50x.html
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    }
    

    生产.rb

    config.action_cable.url = "/cable"
    config.action_cable.allowed_request_origins = ["http://139.59.175.34"]
    

    电缆.js

    (function() {
      this.App || (this.App = {});
    
      App.cable = ActionCable.createConsumer("/cable");
    
    }).call(this);
    

    config/production.rb 收件人:

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

    但还是没有运气。


    WebSocket error occurred: One or more reserved bits are on: reserved1 = 1, reserved2 = 0, reserved3 = 0
    

    更新:

    以下是服务器上的防火墙设置:

    enter image description here

    2 回复  |  直到 6 年前
        1
  •  0
  •   Erowlin Peter    6 年前

    您的配置看起来正确。

    如果运行防火墙,则可能发生此问题。

    如果有什么东西阻塞了iptables配置(linux),请检查iptables配置(不过,我没有一行特定的代码提供给您)。

    更新:你也可以尝试使用 wss://139.59.175.34/cable 而不是 ws://139.59.175.34/cable https://docs.nginx.com/nginx/admin-guide/security-controls/securing-http-traffic-upstream/

        2
  •  0
  •   Ryzal Yusoff    6 年前

    我终于找到了问题的答案。事实证明,我的生产服务器上没有安装redis。所以我只需要安装ReiIS,现在一切都太好了!

    redis-cli

    如果redis控制台出现了,那么您就一切就绪了。如果出现错误/警告,可以按照以下步骤安装并运行redis:

    1. sudo apt install redis-server
    2. redis-server

    希望有帮助!