vidur punj
vidur punj

Reputation: 5871

Rails 5 Error during WebSocket handshake: Unexpected response code: 502

I am using web-socket in my rails application: with Rails 5.2.3, ruby 2.4.0p0, my websocket is working find over http but having following error when I switch to https. The error is as:

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

I have tried changing the configuration in production.rb to

  config.action_cable.url = 'wss://tukaweb.com/cable'
  config.action_cable.allowed_request_origins = [ 'http://tukaweb.com', /http:\/\/tukaweb.*/ ]

and

  config.action_cable.url = [/ws:\/\/*/, /wss:\/\/*/]
  config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]

also added action cable meta tag:

 <%= action_cable_meta_tag %>

But the error still persists, can anybody suggest the correct configuration, thanks and why its working find over http test bed environment but giving error on https with ssl. also I am using Nginx server with passenger module to run rails environment.

Upvotes: 2

Views: 969

Answers (1)

vidur punj
vidur punj

Reputation: 5871

updated the /home/vidur/Downloads/tukaweb/app/assets/javascripts/cable.js to:

//= require action_cable
//= require_self
//= require_tree ./channels

(function() {
  this.App || (this.App = {});

  App.cable =  ActionCable.createConsumer("/cable");

}).call(this);

Production.rb to:

  config.action_cable.url = "/cable"
  config.action_cable.allowed_request_origins = [ 'http://52.35.24.20','http://tukaweb.com', 'https://tukaweb.com' ]

routes.rb to:

  mount ActionCable.server => '/cable'

cable.yml to:

development:
  adapter: redis
  url: redis://localhost:6379/1

test:
  adapter: async

production:
  adapter: redis
  url: redis://localhost:6379/1

updated the virtualhost to:

location /cable {
    passenger_app_group_name tukaweb_action_cable;
    passenger_force_max_concurrent_requests_per_process 0;
}

Upvotes: 1

Related Questions