简体   繁体   English

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

[英]ActionCable Rails 5 (Passenger) - failed: Error during WebSocket handshake: Unexpected response code: 404

I am trying to deploy ActionCable and Rails 5 To Production server (DigitalOcean). 我正在尝试将ActionCable和Rails 5部署到生产服务器(DigitalOcean)。 I have followed all steps mention in the Gorails video here: https://gorails.com/episodes/deploy-actioncable-and-rails-5 我已按照Gorails视频中提到的所有步骤进行操作: https ://gorails.com/episodes/deploy-actioncable-and-rails-5

The app was deployed using Phusion Passenger + Nginx + Capistrano. 该应用程序使用Phusion Passenger + Nginx + Capistrano进行部署。

And when I tried to checked my site on production, I got this error on the browser's console: 当我尝试在生产中检查我的网站时,我在浏览器的控制台上收到了此错误:

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

These are my settings: 这些是我的设置:

/etc/nginx/sites-enabled/default 在/ etc / nginx的/启用的站点- /默认

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

production.rb production.rb

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

cable.js cable.js

(function() {
  this.App || (this.App = {});

  App.cable = ActionCable.createConsumer("/cable");

}).call(this);

I have tried to change the ActionCable config on config/production.rb to: 我试图将config/production.rb上的ActionCable配置更改为:

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

but still no luck. 但仍然没有运气。


I have also looked into the production.log on the server and this is the error that was recorded: 我也查看了服务器上的production.log,这是记录的错误:

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

UPDATE: 更新:

Below is firewall setting on the server: 以下是服务器上的防火墙设置:

在此输入图像描述

Your configuration looks correct. 您的配置看起来正确。

This issue can happens if you have a firewall running. 如果您正在运行防火墙,则会发生此问题。

Check with your iptables configuration (linux) if something is blocking it (I don't have a specific line of code to give to you though). 检查你的iptables配置(linux)是否阻塞了它(虽然我没有特定的代码行)。

If you're on Windows, check that there are no "antivirus" or "firewall" intercepting / blocking the bits. 如果您使用的是Windows,请检查是否有“防病毒”或“防火墙”拦截/阻止这些位。 I heard that Node32 is a very good candidate to block websockets. 我听说Node32是阻止websockets的非常好的候选者。

Update: Can you also try to connect using wss://139.59.175.34/cable instead of ws://139.59.175.34/cable ? 更新:您还可以尝试使用wss://139.59.175.34/cable而不是ws://139.59.175.34/cable进行连接吗? (Be sure your NGinx is proxying with SSL). (确保您的NGinx使用SSL代理)。 https://docs.nginx.com/nginx/admin-guide/security-controls/securing-http-traffic-upstream/ https://docs.nginx.com/nginx/admin-guide/security-controls/securing-http-traffic-upstream/

Finally I found the answer to my problem. 最后我找到了问题的答案。 It turns out that I do not have redis installed on my production server. 事实证明我的生产服务器上没有安装redis。 So I just need to install redis and now everything works great! 所以我只需要安装redis,现在一切都很棒!

To check whether you have redis installed on the server or not, use this command: 要检查服务器上是否安装了redis,请使用以下命令:

redis-cli

If the redis console appear, then you're all set. 如果出现redis控制台,那么你已经完成了设置。 If an error/warning comes out, you can follow these steps to install and run redis: 如果出现错误/警告,您可以按照以下步骤安装并运行redis:

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

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ActionCable - WebSocket 握手期间出错:意外响应代码:404 - ActionCable - Error during WebSocket handshake: Unexpected response code: 404 Rails 5 Actioncable-失败:WebSocket握手期间出错:意外的响应代码:502 - Rails 5 Actioncable - failed: Error during WebSocket handshake: Unexpected response code: 502 WebSocket 握手期间的 Rails 5 错误:意外响应代码:502 - Rails 5 Error during WebSocket handshake: Unexpected response code: 502 在 WebSocket 握手期间 Rails 6 Production ActionCable 错误 - Rails 6 Production ActionCable Error during WebSocket handshake 在websocket握手期间Rails ActionCable错误 - Rails ActionCable error during websocket handshake 带Rails(Puma)的Websockets-WebSocket握手期间出错:意外的响应代码:200 - Websockets with Rails(Puma) - Error during WebSocket handshake: Unexpected response code: 200 WebSocket握手期间出错:意外的响应代码:503 - Error during WebSocket handshake: Unexpected response code: 503 WebSocket握手期间出错:意外的响应代码:502 - Error during WebSocket handshake: Unexpected response code: 502 Actioncable Nginx和Puma WebSocket握手:意外响应 - Actioncable Nginx and Puma WebSocket handshake: Unexpected response Websocket Rails 在握手期间获得 404 - Websocket Rails getting 404 during handshake
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM