こんにちは。 サーバーサイドがrails(APIモード)、フロントはreactのspaアプリケーションで actionケーブルを使ってリアルタイムアップデートのchat機能を実装しています。
表題の通り、以下のエラーが継続的に発生し、production環境でactioncableが動作しません。ローカル環境では問題なく動いています。
解決の糸口すらつかめずにいます。 どなたかご教授いただけないでしょうか。 よろしくお願い申し上げます。
rails 5.2.1
puma 3.12.0
ruby 2.4.6
nginx 1.12.2
redis 4.0.10
aws elasticache
エラー
main.js:89513 WebSocket connection to 'wss://myapp.com:3000/cable' failed: WebSocket is closed before the connection is established
frontend/index.js
js
1import ActionCable from 'actioncable' 2 3ActionCable.createConsumer(`wss://myapp.com:3000/cable?authorization=${tokens['Authorization']}&firebaseUID=${tokens['FirebaseUID']}`)
config/environments/production.rb
ruby
1 config.action_cable.url = 'wss://myapp.com/cable:3000' 2 config.action_cable.allowed_request_origins = [ 'http://myapp.com', /http://myapp.*/, 'https://myapp.com', /https://myapp.*/ ]
nginx.conf
nginx
1 2upstream puma { 3 server unix:///srv/myapp/tmp/sockets/puma.sock; 4} 5 6location / { 7 try_files $uri $uri/index.html $uri.html @webapp; 8 } 9 10location @webapp { 11 proxy_read_timeout 300; 12 proxy_connect_timeout 300; 13 proxy_redirect off; 14 proxy_set_header X-Forwarded-Proto $scheme; 15 proxy_set_header Host $http_host; 16 proxy_set_header X-Real-IP $remote_addr; 17 proxy_pass http://puma; 18 } 19 20 21 22location /cable { 23 proxy_pass http://puma/cable; 24 proxy_http_version 1.1; 25 proxy_set_header Upgrade $http_upgrade; 26 proxy_set_header Connection "upgrade"; 27}
config/cable.yml
yml
1production: 2 adapter: redis 3 url: ENV['ELASTIC_CACHE_URL']} <= elasticache(redis4.0)のエンドポイント
あなたの回答
tips
プレビュー