Actioncable Nginx和Puma WebSocket握手:意外响应 [英] Actioncable Nginx and Puma WebSocket handshake: Unexpected response

查看:164
本文介绍了Actioncable Nginx和Puma WebSocket握手:意外响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Rails 5,Nginx和Puma配置服务器.该应用程序运行正常,但Actioncable给出了

I am trying to configure the server with rails 5, Nginx and Puma. The application is running fine but Actioncable is giving

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

以下是我的Nginx设置

Below are my nginx settings,

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

在production.rb的rails中,我进行了如下设置.

In rails in production.rb, I did the settings like below.

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

任何帮助将不胜感激.

Any help will be appreciated.

推荐答案

尝试添加:

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

到您的config/environments/production.rb文件

与我合作,您可以检查此链接也. 和此问题

it works with me, you can check this link also. and this question

这篇关于Actioncable Nginx和Puma WebSocket握手:意外响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆