Rails 5 Action Cable deployment with Nginx, Puma & Redis

為{幸葍}努か 提交于 2019-12-22 03:42:06

问题


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.

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

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.

Things I've tried:

  • 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";
    }
    
  • Setting Rails.application.config.action_cable.allowed_request_origins to the proper host (tried "http://{server-ip}" and "ws://{server-ip}")

  • Turning on Rails.application.config.action_cable.disable_request_forgery_protection

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.


回答1:


Finally, I got it working! I've been trying various things for about a week...

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.



来源:https://stackoverflow.com/questions/35928227/rails-5-action-cable-deployment-with-nginx-puma-redis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!