【问题标题】:Rails 5 Action Cable deployment with Nginx, Puma & Redis使用 Nginx、Puma 和 Redis 部署 Rails 5 Action Cable
【发布时间】:2016-03-10 22:02:24
【问题描述】:

我正在尝试使用 Capistrano 将启用 Action Cable 的应用程序部署到 VPS。我正在使用 Puma、Nginx 和 Redis(用于 Cable)。经过几个障碍,我能够让它在本地开发环境中工作。我正在使用默认的进程内 /cable URL。但是,当我尝试将其部署到 VPS 时,我在 JS 日志中不断收到这两个错误:

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-prompt 中打开 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}”)

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

运气不好。是什么导致了这个问题?

$ rails -v
Rails 5.0.0.beta3

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

【问题讨论】:

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


    【解决方案1】:

    终于,我成功了!我已经尝试了大约一周的各种事情......

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

    【讨论】:

      猜你喜欢
      • 2018-03-28
      • 1970-01-01
      • 2018-01-30
      • 2019-12-30
      • 2018-08-24
      • 1970-01-01
      • 2015-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多