我正在使用Rails(api模式)创建实时更新聊天应用程序,并使用以下技术做出反应。
1.rails 5.2.1 2.彪马3.12.0 3.红宝石2.4.6 4.nginx 1.12.2 5.版本4.0.10 6.aws弹性疼痛
frontend/index.js
import ActionCable from 'actioncable'
ActionCable.createConsumer(`wss://myapp.com:3000/cable?authorization=${tokens['Authorization']}&firebaseUID=${tokens['FirebaseUID']}`)
config/environments/production.rb
config.action_cable.url = 'wss://myapp.com/cable:3000'
config.action_cable.allowed_request_origins = [ 'http://myapp.com', /http:\/\/myapp.*/, 'https://myapp.com', /https:\/\/myapp.*/ ]
nginx.conf
upstream puma {
server unix:///srv/myapp/tmp/sockets/puma.sock;
}
location / {
try_files $uri $uri/index.html $uri.html @webapp;
}
location @webapp {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://puma;
}
location /cable {
proxy_pass http://puma/cable;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
config/cable.yml
production:
adapter: redis
url: ENV['ELASTIC_CACHE_URL']} <= endpoint of elasticache(redis4.0)
但是我遇到了以下错误。
main.js:89513与'wss://myapp.com:3000 / cable'的WebSocket连接失败:在建立连接之前关闭WebSocket
有人可以给我建议吗?