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 6 Production ActionCable Error during WebSocket handshake
After a few days, I managed to solve this problem myself.
The main reason for my error is that in my environments / production.rb file, I was saying that the actioncable endpoint was the public ip of my ec2. But in reality you should put localhost. I used the same configuration I have in development.rb:
production.rb before:
...
config.action_cable.mount_path = '/cable'
config.action_cable.url = 'ws://my_ec2/cable'
config.action_cable.allow_same_origin_as_host = true
config.action_cable.allowed_request_origins = ["*"]
...
production.rb after:
...
config.action_cable.disable_request_forgery_protection = true
config.action_cable.url = "ws://localhost:3000/cable"
config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]
config.action_cable.allowed_request_origins = /(\.dev$)|^localhost$/
...
Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: , HTTP_UPGRADE: )
May be you need some config in your nginx configuration? I do not really worked with passenger, but in my project I use it like:
upstream socket_server {
server <your_ip>:<your_port>;
}
location /cable {
proxy_pass http://socket_server;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
I use anycable gem, with golang
socket server, and it may have differences with passenger
and default actioncable
but may be my answer can help to rid of your problem
(Also, I strongly recommend to move on anycable
because it is consumes the least server resources:))
Related Topics
Ruby on Rails Country/State Select Enigma
Parse Large JSON Hash with Ruby-Yajl
What Are Some Good Role Authorization Solutions Used with Authlogic
Authlogic Perishable_Token Resets on Every Request
Convert Timestamp Timezone in Logstash for Output Index Name
Recovering from a Broken Tcp Socket in Ruby When in Gets()
How to Scrape Pages Which Have Lazy Loading
How to Use Objects with Xsi:Types in Savon
Finding the Product of a Variable Number of Ruby Arrays
How to Tell Which Openssl Lib Is Actually Being Used by an Rvm-Installed Ruby
Open-Uri Returning Ascii-8Bit from Webpage Encoded in Iso-8859
In Rails, How to Access Response.Body in a Action Before It Returns
Wicked_Pdf: Footer Height/Styling
Ruby Convert Idn Domain from Punycode to Unicode