【问题标题】:Action cable not working in rails 5.1.7 on production environment动作电缆在生产环境中的 rails 5.1.7 中不起作用
【发布时间】:2020-09-04 20:37:22
【问题描述】:

我使用带有 rails 5.1.7 的动作电缆,它在本地的开发环境和生产环境中运行良好,但是当它部署在 aws ec2 上时它无法运行。下面是action cable config的production.rb代码。

config.action_cable.url = 'wss://example.com/cable'
config.action_cable.allowed_request_origins = ["https://example.com", "https://www.example.com"]
config.action_cable.mount_path = '/cable/:token'
ActionCable.server.config.disable_request_forgery_protection = true

下面提到了cable.yml。

development:
  adapter: async

test:
  adapter: async

production:
  adapter: redis
  url: redis://localhost:6379/1

但默认安装路径get /cable 不在服务器配置级别调用。如果我正在调用 wss://example.com/cable,那么它正在连接,但默认在页面加载时它没有连接。

【问题讨论】:

    标签: ruby-on-rails actioncable ruby-on-rails-5.2 ruby-on-rails-5.1 redis-server


    【解决方案1】:

    尝试安装redis插件,如下。我的代码使用了这个:

    cable.yml

    production:
        adapter: redis
        url: <%= ENV.fetch("REDISCLOUD_URL") { "redis://localhost:6379/1" } %>
        channel_prefix: _YourAppName_production
    

    然后,在生产环境中安装(我的是在 heroku 上):

    heroku addons:create rediscloud:30
    

    而且我不需要 production.rb 中的 action_cable 设置,如果您保持 'myexample' 表达式不变,它将无法工作。

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 1970-01-01
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      • 2012-08-09
      • 2018-09-19
      • 2019-01-04
      • 1970-01-01
      相关资源
      最近更新 更多