Rails 5动作电缆部署与Nginx,Puma& Redis的

时间:2016-03-10 22:02:25

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

我正在尝试使用Capistrano将Action Cable -enabled-application部署到VPS。我正在使用Puma,Nginx和Redis(用于Cable)。经过几次跨栏后,我能够在当地的开发环境中工作。我使用的是默认的进程内/有线网址。但是,当我尝试将其部署到VPS时,我不断在JS-log中得到这两个错误:

Establishing connection to host ws://{server-ip}/cable failed.
Connection to host ws://{server-ip}/cable was interrupted while loading the page.

在我的应用专用nginx.error.log我收到这些消息:

2016/03/10 16:40:34 [info] 14473#0: *22 client 90.27.197.34 closed keepalive connection

在JS提示中打开ActionCable.startDebugging()没有任何兴趣。只是ConnectionMonitor尝试无限期地重新打开连接。我也获得了301的负载:永久移动 - 在我的网络监视器中请求/ cable。

我尝试过的事情:

  • 使用async适配器代替Redis。 (这是开发环境中使用的内容)
  • 将这样的内容添加到我的/etc/nginx/sites-enabled/{app-name}

    location /cable/ {
      proxy_pass http://puma;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "Upgrade";
    }
    
  • Rails.application.config.action_cable.allowed_request_origins设置为正确的主机(已尝试" http:// {server-ip}"和" ws:// {server-ip}& #34)

  • 开启Rails.application.config.action_cable.disable_request_forgery_protection

没有运气。造成这个问题的原因是什么?

$ rails -v
Rails 5.0.0.beta3

请告知我可能有用的任何其他详细信息。

1 个答案:

答案 0 :(得分:13)

最后,我明白了!我已经尝试了大约一个星期的各种事情......

301重定向是由nginx实际上试图将浏览器重定向到/ cable /而不是/ cable引起的。这是因为我在location节中指定了/ cable /而不是/ cable!我从this answer得到了这个想法。