我正在尝试使用 Capistrano 将启用 Action Cable 的应用程序部署到 VPS。我正在使用 Puma、Nginx 和 Redis(用于电缆)。经过几个障碍后,我能够让它在本地开发环境中运行。我正在使用默认的进程内 /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
正在开启ActionCable.startDebugging()
JS 提示中没有显示任何有趣的内容。只是 ConnectionMonitor 试图无限期地重新打开连接。我的网络监视器中还收到了 301: Moved permanent -requests for /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";
}
Setting 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
请告知我任何可能有用的其他详细信息。
终于,我成功了!我已经尝试了大约一周的各种事情......
301 重定向是由 nginx 实际上尝试将浏览器重定向到 /cable/ 而不是 /cable 引起的。这是因为我在中指定了 /cable/ 而不是 /cablelocation
节!我的想法来自这个答案 https://stackoverflow.com/a/25502657/3719597.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)