我对 ActionCable 完全陌生...尝试在 Rails 6.0 应用程序(Nginx + Puma)上设置 Action Cable。我还必须说我的环境是在云上(DigitalOcean.com),那就是 SSL。
我的config/cable.yml:
development:
adapter: redis
url: redis://localhost:6379
我的 config/environments/development.rb :我刚刚添加了这行
config.action_cable.allowed_request_origins = ["https://my.url.com/"]
config.action_cable.url = "ws://localhost:3000/cable"
当然:my.url.com 是我的域名。
我收到此错误:
WebSocket connection to 'wss://my.url.com/cable' failed: WebSocket is closed before the connection is established.
有人有想法吗?
非常感谢:-)
最佳答案
将位置 block 添加到您的 nginx 配置文件中。
location /cable {
proxy_pass http://puma_app;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
将 puma_app
替换为您的上游名称。
关于ruby-on-rails - ActionCable - Puma - Nginx - SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65028958/