【发布时间】:2021-01-02 06:01:56
【问题描述】:
Rails 5 有一个类似的 - 未回答的 - 问题,但是,由于我使用的是 Rails 6,所以我再次询问。
我在生产环境中使用动作电缆时遇到了一些麻烦。 开发环境运行良好。
要解决的错误:WebSocket connection to 'wss://myapp.com/cable' failed: WebSocket is closed before the connection is established.
我在 Chrome 的控制台上多次收到此错误。
堆栈
- Ruby 2.6.5
- Rails 6.0.3.2
- Nginx 1.14.0
nginx.conf
server {
listen 443 ssl;
server_name *.myapp.com;
ssl_certificate /etc/letsencrypt/live/myapp.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/myapp.com/privkey.pem;
root /home/deploy/myapp/current/public;
passenger_enabled on;
passenger_app_env production;
location /cable {
passenger_app_group_name myapp_websocket;
passenger_force_max_concurrent_requests_per_process 0;
}
# Allow uploads up to 100MB in size
client_max_body_size 100m;
location ~ ^/(assets|packs) {
expires max;
gzip_static on;
}
}
cable.yml
development:
adapter: redis
test:
adapter: test
production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: myapp_production
production.rb
config.action_cable.url = 'wss://app.myapp.com/cable'
config.action_cable.allowed_request_origins = [ 'https://app.myapp.com' ]
这些行在日志中不断重复: log/production.log
I, [2020-09-15T13:05:02.679580 #32158] INFO -- : Finished "/cable/" [WebSocket] for xxx.xxx.133.88 at 2020-09-15 13:05:02 +0000
I, [2020-09-15T13:05:03.791781 #32158] INFO -- : [2c7c3ddf-e0d9-4f6b-80d5-ace193462c8a] Started GET "/cable" for xxx.xxx.133.88 at 2020-09-15 13:05:03 +0000
I, [2020-09-15T13:05:03.792248 #32158] INFO -- : [2c7c3ddf-e0d9-4f6b-80d5-ace193462c8a] Started GET "/cable/" [WebSocket] for xxx.xxx.133.88 at 2020-09-15 13:05:03 +0000
I, [2020-09-15T13:05:03.792320 #32158] INFO -- : [2c7c3ddf-e0d9-4f6b-80d5-ace193462c8a] Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPG
浏览器控制台
WebSocket connection to 'wss://app.myapp.com/cable' failed: WebSocket is closed before the connection is established.
【问题讨论】:
标签: ruby-on-rails nginx websocket actioncable