Question

How to configure Redis/ActionCable on Nginx/Puma server ?

My droplet : Ruby on Rails 6.0.3.4 on Ubuntu 20.04 | Nginx | Puma | SSL

I’m totally new to ActionCable, and trying to set up Actioncable on my Rails application.

My config/cable.yml :

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

My config/environments/development.rb : i’ve just added this lines

config.action_cable.allowed_request_origins = ["https://my.url.com/"]
config.action_cable.url = "ws://localhost:3000/cable"

Of course: my.url.com is my domain.

My Nginx

upstream websocket {
     server 127.0.0.1:6379;
}

server {

  ....


  location /cable {
    proxy_pass https://websocket/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto https;
    proxy_redirect off;
  }
}

I’m getting this error :

WebSocket connection to 'wss://my.url.com/cable' failed: WebSocket is closed before the connection is established.

Does anyone have a idea ?

Thanks a lot :-)


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

proxy_set_header        X-Forwarded-Proto $scheme;
proxy_set_header        X-Forwarded-Host $host;