Nginx,Puma和amp; amp;的Rails 5 Action Cable部署雷迪斯 [英] Rails 5 Action Cable deployment with Nginx, Puma & Redis
问题描述
我正在尝试使用Capistrano将启用了Action Cable的应用程序部署到VPS.我正在使用Puma,Nginx和Redis(用于电缆).经过几次障碍后,我得以使其在本地开发环境中工作.我正在使用默认的进程内/cable URL.但是,当我尝试将其部署到VPS时,我在JS日志中不断遇到这两个错误:
I am trying to deploy an Action Cable -enabled-application to a VPS using Capistrano. I am using Puma, Nginx, and Redis (for Cable). After a couple hurdles, I was able to get it working in a local developement environment. I'm using the default in-process /cable URL. But, when I try deploying it to the VPS, I keep getting these two errors in the 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
中,我收到以下消息:
And in my app-specific nginx.error.log
I'm getting these messages:
2016/03/10 16:40:34 [info] 14473#0: *22 client 90.27.197.34 closed keepalive connection
在JS提示符下打开ActionCable.startDebugging()
不会显示任何有趣的内容.只是ConnectionMonitor尝试无限期地重新打开连接.我的负载也为301:永久移动-在我的网络监视器中对/cable的请求.
Turning on ActionCable.startDebugging()
in the JS-prompt shows nothing of interest. Just ConnectionMonitor trying to reopen the connection indefinitely. I'm also getting a load of 301: Moved permanently -requests for /cable in my network monitor.
- 使用
async
适配器而不是Redis. (这就是开发环境中使用的内容) -
在我的
/etc/nginx/sites-enabled/{app-name}
中添加这样的内容:
- Using the
async
adapter instead of Redis. (This is what is used in the developement env) Adding something like this to my
/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}"")
Setting Rails.application.config.action_cable.allowed_request_origins
to the proper host (tried "http://{server-ip}" and "ws://{server-ip}")
没有运气.是什么原因引起的?
No luck. What is causing the issue?
$ rails -v
Rails 5.0.0.beta3
请告知我任何可能有用的其他详细信息.
Please inform me of any additional details that may be useful.
推荐答案
最后,我成功了!我已经尝试了大约一个星期的各种事情...
Finally, I got it working! I've been trying various things for about a week...
301重定向是由nginx实际试图将浏览器重定向到/cable/而不是/cable引起的.这是因为我在location
节中指定了/cable/而不是/cable!我是从此答案中得到的想法.
The 301-redirects were caused by nginx actually trying to redirect the browser to /cable/ instead of /cable. This is because I had specified /cable/ instead of /cable in the location
stanza! I got the idea from this answer.
这篇关于Nginx,Puma和amp; amp;的Rails 5 Action Cable部署雷迪斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!