1

I'm getting this error for actioncable when I switched my site to https:

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

The https site works fine, but I get a 404 for the websocket address. My current setup has the SSL terminate at the ELB and nginx redirect http to https. I run actioncable together with my rail server, not as a standalone.

How would I set up secure websockets in ?

Here is my nginx conf file

upstream puma {
  server unix://var/run/server.sock;
}

server {
  listen 80;
  server_name default_server;

  root /var/www/apps/server/public;

  location /cable {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_pass http://puma;
  }

  location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_next_upstream error;

   if ($http_x_forwarded_proto != "https") {
     rewrite ^(.*)$ https://$host$1 permanent;
   }

  proxy_pass http://puma;

  ...

}

And here is the configuration on ELB:

ELB Listeners

oniiko
  • 41
  • 6
  • 1
    Update ELB Listener from Secure HTTPS to Secure TCP did the trick - see https://stackoverflow.com/questions/25730368/websockets-wss-from-client-to-amazon-aws-ec2-instance-through-elb – Jirapong Jun 27 '17 at 11:11

1 Answers1

0

Fixed similar error (404 in actioncable /cable) in my setup like this

location /cable {
    proxy_pass http://unix:/home/app/shared/tmp/puma/socket;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Host $host:$server_port;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 86400;
}

so add same proxy_set_header as you have in the other location (X-Real-IP etc)

glebtv
  • 3,739
  • 1
  • 22
  • 10