ruby-on-rails - ActionCable - Puma - Nginx - SSL

标签 ruby-on-rails nginx redis puma actioncable

我对 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/

相关文章:

caching - nginx:将条件过期 header 添加到 fastcgi_cache 响应

NGINX RTMP 将 flv 转换为 hls?

php - 尝试为 Windows 编译 phpredis

ruby-on-rails - brew 安装 redis (osx 10.7)

python - 当我将 PostgreSQL 作为 Django 的数据库时,为什么要使用 Redis?

django + nginx https 重定向显示 (414 Request-URI Too Large)

mysql - 如何将我当前的大型 Mysql 数据库转换为 Rails 4.2

mysql - 从 ActiveRecord::Relation 获取 SQL 数组

ruby-on-rails - 存储用户银行帐户信息的最佳方式?

ruby-on-rails - 使用 ruby​​ 访问浏览器的公共(public) `window` 属性