简体   繁体   English

Actioncable Nginx和Puma WebSocket握手:意外响应

[英]Actioncable Nginx and Puma WebSocket handshake: Unexpected response

I am trying to configure the server with rails 5, Nginx and Puma. 我正在尝试使用Rails 5,Nginx和Puma配置服务器。 The application is running fine but Actioncable is giving 该应用程序运行正常,但Actioncable给出了

WebSocket connection to 'ws://server_name.com/cable' failed:
Error during WebSocket handshake: Unexpected response code: 200

Below are my nginx settings, 以下是我的Nginx设置,

upstream app {
  server unix:/tmp/app.sock fail_timeout=0;
}

server {
    listen       80;
    server_name  server_name.com;
    try_files $uri/index.html $uri @app;
    client_max_body_size 100M;
    location @app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://app;
      client_max_body_size 10M;
    }

    location /cable {
       proxy_pass http://app/;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "Upgrade";
    }

    location ~ ^/(assets|uploads)/ {
        root assets_path;
        gzip_static on;
        expires max;
        add_header Cache-Control public;
        add_header ETag "";
        break;
    }
    error_page   500 502 503 504  /500.html;
 }

In rails in production.rb, I did the settings like below. 在production.rb的rails中,我进行了如下设置。

config.action_cable.url = 'ws://server_name.com/cable'

Any help will be appreciated. 任何帮助将不胜感激。

try to add: 尝试添加:

config.action_cable.allowed_request_origins = ['*']
config.action_cable.disable_request_forgery_protection = true

to your config/environments/production.rb file 到您的config/environments/production.rb文件

it works with me, you can check this link also. 它对我有效,您也可以检查此链接 and this question 这个问题

Try using, 尝试使用

location /cable {
    proxy_pass http://app; # not http://app/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
}

And also make sure that you have config.action_cable.allowed_request_origins = [/http:\\/\\/*/, /https:\\/\\/*/] in your production.rb if you don't have ssl 如果没有ssl,请确保在production.rb中有config.action_cable.allowed_request_origins = [/http:\\/\\/*/, /https:\\/\\/*/]

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

相关问题 ActionCable - WebSocket 握手期间出错:意外响应代码:404 - ActionCable - Error during WebSocket handshake: Unexpected response code: 404 ActionCable / Websocket无法与Puma一起使用 - ActionCable / Websocket not working with Puma ActionCable Rails 5(Passenger) - 失败:WebSocket握手期间出错:意外响应代码:404 - ActionCable Rails 5 (Passenger) - failed: 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 带Rails(Puma)的Websockets-WebSocket握手期间出错:意外的响应代码:200 - Websockets with Rails(Puma) - Error during WebSocket handshake: Unexpected response code: 200 ActionCable - Puma - Nginx - SSL - ActionCable - Puma - Nginx - SSL Websocket导轨(Faye-websocket)握手错误代码200-AWS ElasticBeanstalk,nginx,puma - Websocket rails (Faye-websocket) handshake error code 200 - AWS ElasticBeanstalk, nginx, puma ActionCable + Nginx + Puma和java.io.EOFException - ActionCable + Nginx + Puma and java.io.EOFException 在 WebSocket 握手期间 Rails 6 Production ActionCable 错误 - Rails 6 Production ActionCable Error during WebSocket handshake 在websocket握手期间Rails ActionCable错误 - Rails ActionCable error during websocket handshake
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM