1

I'm trying to get a Rails 5.0 app with ActionCable deployed on Elastic Beanstalk running Nginx and Puma.

In .ebextensions/nginx.config I have the following:

location /cable { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade websocket; proxy_set_header Connection upgrade; }

and in config/environments/production.rb

config.action_cable.allowed_request_origins = [ 'http://####.####.com', /http:\/\/####.*/ ]

After deploying the app to the Elastic Beanstalk environment I end up with this error in the Chrome console:

WebSocket connection to 'ws://####.####.com/cable' failed: WebSocket is closed before the connection is established.

I've tried following the advice in this thread but end up getting this error instead:

WebSocket connection to 'ws://####.####.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

This is what my .ebextensions/nginx.config file looks like currently.

Any help would be greatly appreciated.

Community
  • 1
  • 1
Marcelo Alves
  • 313
  • 2
  • 7

1 Answers1

2

Turns out the connection was being killed at the Elastic Load Balancer. ELB Listeners were set to HTTP and needed to be TCP.

Marcelo Alves
  • 313
  • 2
  • 7
  • Would you mind about sharing some additional information? In line: proxy_pass `http://backend`; should I change to `http://my_backend_host_etc.com` ? – Pasp Ruby May 04 '17 at 20:23
  • @PaspRuby for my setup I have this in the `nginx.conf`: ```upstream backend { server unix:///var/run/puma/my_app.sock; }``` So the `proxy_pass` line is referencing that upstream value and points directly to the running puma server – Marcelo Alves May 05 '17 at 20:32
  • I'm running into the same problem, getting `WebSocket connection to 'ws://####.####.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 404` What do you have for listeners @MarceloAlves? I have this: Listener 1: Port 80 HTTP, Instance port 80 Instance protocol HTTP; Listener 2: Port 443 HTTPS, Instance port 80 Instance protocol HTTP. – Jack Feb 12 '19 at 01:22
  • 1
    @Jack Hey there. Unfortunately we stopped using websockets long ago and upgraded to the newer Application Load Balancer which reset the listeners to HTTP. I believe in order for websockets to work on the Classic LB it needs to be set to TCP – Marcelo Alves Feb 13 '19 at 18:19