使用Nginx,Puma和Redis进行Rails 5 Action Cable部署

oll*_*lpu 11 nginx puma ruby-on-rails-5

我正在尝试使用Capistrano将Action Cable -enabled-application部署到VPS.我正在使用Puma,Nginx和Redis(用于Cable).经过几次跨栏后,我能够在当地的开发环境中工作.我正在使用默认的进程内/有线URL.但是,当我尝试将其部署到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.
Run Code Online (Sandbox Code Playgroud)

在我的应用程序特定中,nginx.error.log我收到这些消息:

2016/03/10 16:40:34 [info] 14473#0: *22 client 90.27.197.34 closed keepalive connection
Run Code Online (Sandbox Code Playgroud)

ActionCable.startDebugging()在JS提示中打开显示没有任何兴趣.只是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";
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • 设置Rails.application.config.action_cable.allowed_request_origins为正确的主机(尝试"http:// {server-ip}"和"ws:// {server-ip}")

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

没运气.是什么导致了这个问题?

$ rails -v
Rails 5.0.0.beta3
Run Code Online (Sandbox Code Playgroud)

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

oll*_*lpu 13

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

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