Ruby on rails 轨道&x2B;ActionCable&x2B;乘客+;AWS Elasticache(Redis):如何修复&x27;在建立连接之前关闭WebSocket;关于生产?

Ruby on rails 轨道&x2B;ActionCable&x2B;乘客+;AWS Elasticache(Redis):如何修复&x27;在建立连接之前关闭WebSocket;关于生产?,ruby-on-rails,ruby,websocket,passenger,actioncable,Ruby On Rails,Ruby,Websocket,Passenger,Actioncable,我在生产环境中操作动作电缆时遇到一些问题开发环境工作正常。 要解决的错误: WebSocket连接到'wss://myapp.com/cable'失败:在建立连接之前关闭WebSocket 我在Chrome的控制台上多次遇到这个错误 堆栈 Ruby 2.3.0 轨道5.0.7.2 Nginx 1.10.1 乘客5.0.30 Redis 5.0.3(在AWS Elasticache上) nginx.conf server { listen 443 ssl; server_name my

我在生产环境中操作动作电缆时遇到一些问题开发环境工作正常。

要解决的错误: WebSocket连接到'wss://myapp.com/cable'失败:在建立连接之前关闭WebSocket

我在Chrome的控制台上多次遇到这个错误

堆栈

  • Ruby 2.3.0
  • 轨道5.0.7.2
  • Nginx 1.10.1
  • 乘客5.0.30
  • Redis 5.0.3(在AWS Elasticache上)
nginx.conf

server {
  listen 443 ssl;
  server_name myapp.com *myapp.com;
  root /home/ubuntu/myapp/current/public;
  ssl_certificate ...;
  ssl_certificate_key ...;
  passenger_enabled on;
  passenger_min_instances 1;
  ...

  location /cable {
    passenger_app_group_name my_app_action_cable;
    passenger_force_max_concurrent_requests_per_process 0;
  }
}
cable.yml

production:
  adapter: redis
  url: redis://myapp.grzdsm.0001.euw1.cache.amazonaws.com:6379
production.rb

config.action_cable.url = "wss://myapp.com/cable"
config.action_cable.allowed_request_origins = ["https://myapp.com", "myapp.com"]
mount ActionCable.server => '/cable'
class NotificationChannel < ApplicationCable::Channel

  def subscribed
    stream_from "notification"
  end

  def unsubscribed
  end

end
module ApplicationCable
  class Connection < ActionCable::Connection::Base
  end
end
module ApplicationCable
  class Channel < ActionCable::Channel::Base
  end
end
routes.rb

config.action_cable.url = "wss://myapp.com/cable"
config.action_cable.allowed_request_origins = ["https://myapp.com", "myapp.com"]
mount ActionCable.server => '/cable'
class NotificationChannel < ApplicationCable::Channel

  def subscribed
    stream_from "notification"
  end

  def unsubscribed
  end

end
module ApplicationCable
  class Connection < ActionCable::Connection::Base
  end
end
module ApplicationCable
  class Channel < ActionCable::Channel::Base
  end
end
通知\u channel.rb

config.action_cable.url = "wss://myapp.com/cable"
config.action_cable.allowed_request_origins = ["https://myapp.com", "myapp.com"]
mount ActionCable.server => '/cable'
class NotificationChannel < ApplicationCable::Channel

  def subscribed
    stream_from "notification"
  end

  def unsubscribed
  end

end
module ApplicationCable
  class Connection < ActionCable::Connection::Base
  end
end
module ApplicationCable
  class Channel < ActionCable::Channel::Base
  end
end
通知。咖啡

App.notification = App.cable.subscriptions.create "NotificationChannel",
  connected: ->
    console.log("connected");

  disconnected: ->
    console.log("disconnected");

  received: (data) ->
    console.log("received");
我的日志显示websocket连接成功

I, [2019-05-06T11:00:57.688540 #4986]  INFO -- : Finished "/cable/" [WebSocket] for 144.85.191.180 at 2019-05-06 11:00:57 +0200
I, [2019-05-06T11:01:09.799045 #4986]  INFO -- : Started GET "/cable/" [WebSocket] for 144.85.191.180 at 2019-05-06 11:01:09 +0200
I, [2019-05-06T11:01:09.799154 #4986]  INFO -- : Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)
I, [2019-05-06T11:01:09.803010 #4986]  INFO -- : Registered connection (Z2lkOi8veXBqL1VzZXIvMjkx)
I, [2019-05-06T11:01:20.541988 #4986]  INFO -- : Finished "/cable/" [WebSocket] for 144.85.191.180 at 2019-05-06 11:01:20 +0200
I, [2019-05-06T11:01:21.784567 #4986]  INFO -- : Started GET "/cable/" [WebSocket] for 144.85.191.180 at 2019-05-06 11:01:21 +0200
I, [2019-05-06T11:01:21.784672 #4986]  INFO -- : Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)
I, [2019-05-06T11:01:21.788734 #4986]  INFO -- : Registered connection (Z2lkOi8veXBqL1VzZXIvMjkx)
I, [2019-05-06T11:01:43.768741 #4986]  INFO -- : Finished "/cable/" [WebSocket] for 144.85.191.180 at 2019-05-06 11:01:43 +0200
I, [2019-05-06T11:01:44.784226 #4986]  INFO -- : Started GET "/cable/" [WebSocket] for 144.85.191.180 at 2019-05-06 11:01:44 +0200
I, [2019-05-06T11:01:44.784333 #4986]  INFO -- : Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)
I, [2019-05-06T11:01:44.788154 #4986]  INFO -- : Registered connection (Z2lkOi8veXBqL1VzZXIvMjkx)
Redis监视器显示订阅和取消订阅

1557133304.788584 [0 172.30.1.177:59731] "subscribe" "action_cable/Z2lkOi8veXBqL1VzZXIvMjkx"
1557133326.654308 [0 172.30.1.177:59731] "unsubscribe" "action_cable/Z2lkOi8veXBqL1VzZXIvMjkx"
1557133327.910010 [0 172.30.1.177:59731] "subscribe" "action_cable/Z2lkOi8veXBqL1VzZXIvMjkx"
1557133349.255254 [0 172.30.1.177:59731] "unsubscribe" "action_cable/Z2lkOi8veXBqL1VzZXIvMjkx"
1557133351.183697 [0 172.30.1.177:59731] "subscribe" "action_cable/Z2lkOi8veXBqL1VzZXIvMjkx"
1557133356.974099 [0 172.30.1.177:59731] "unsubscribe" "action_cable/Z2lkOi8veXBqL1VzZXIvMjkx"
1557133357.707420 [0 172.30.1.177:59731] "subscribe" "action_cable/Z2lkOi8veXBqL1VzZXIvMjkx"
1557133371.886670 [0 172.30.1.177:59731] "unsubscribe" "action_cable/Z2lkOi8veXBqL1VzZXIvMjkx"
但我仍然得到这个错误:WebSocket连接到'wss://myapp.com/cable'失败:在建立连接之前关闭WebSocket


任何线索都将不胜感激,谢谢

您可能需要更改'wss://...'到您的config/environments/production.rb文件中的'ws://…'

我无法连接操作电缆,它没有调用我,[2019-05-06T11:00:57.688540(4986]信息--:2019-05-06 11:00:57+0200 I,[2019-05-06T11:01:09.799045(4986]信息--:“/cable/”,而production.rb和all的设置是相同的。您能告诉我为什么它没有在服务器加载时调用/cable吗。我在Rails 6中遇到了同样的问题-我将提出一个新问题。