Make WebSocket work with Ruby on Rails vs Puma and Nginx
The problem was in the config/application.rb
file. I've set correctly the following config option: config.action_cable.url = https://test.mysite.com
however didn't set the config.action_cable.allowed_request_origins
Correct config/application.rb
file should look like this:
require 'active_model/railtie'
require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'action_view/railtie'
require 'action_cable/engine'
require 'sprockets/railtie'
Bundler.require(*Rails.groups)
module MyModule
class Application < Rails::Application
...
config.action_cable.url = https://test.mysite.com
config.action_cable.allowed_request_origins = [/https:\/\/test.mysite.com/]
...
end
end
How to connect to a websocket API with Rails?
ActionCable is for setting up websocket servers. It sounds like you are looking for a websocket client. You could check out this gem as a starting point: https://github.com/shokai/websocket-client-simple
Rails 6 ActionCable Unable to Upgrade WebSocket Request
After posting on reddit, I was able to fix my issue by:
- Removing my
.ebextensions/nginx_proxy.config
file. - Creating a new file,
.platform/nginx/conf.d/elasticbeanstalk/websocket.conf
with the contents:
location /cable {
proxy_pass http://my_app/cable;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Rails and WebSockets using SSL/TLS in development environment
The solution was to visit https://my.app.eu:28080/ and accept the certificate, then the WSS connections are working.
Related Topics
M Hartl's Ruby on Rails Tutorial Chapter 5 Custom Title on Home Page
File.Open, Open and Io.Foreach in Ruby, What Is the Difference
How to Generate a Random Number Between a and B in Ruby
If Java People Go to Scala, C# Go to F#, Where Do Ruby People Go for Functional Nirvana
How to Customize Gemfile Per Developer
Puppet/Facter "Could Not Retrieve Fact Fqdn": How to Fix or Circumvent
Why Does Ruby Open-Uri's Open Return a Stringio in My Unit Test, But a Fileio in My Controller
How to Check If a Param Is True or False
Passing Parameters to Erb View
How to Use Ruby's Readlines.Grep for Utf-16 Files
Will Uuid as Primary Key in Postgresql Give Bad Index Performance
Ruby - Elegantly Convert Variable to an Array If Not an Array Already
How to Set an Attr_Accessor for a Dynamic Instance Variable
Rspec: How to Test File Operations and File Content