Deploy ActionCable in production

A guide on how to deploy ActionCable in a production environment

ActionCable is the new websocket implementation included in Rails 5. Here's how to deploy it to production! Please note a lot of this is changing quickly so not everything may work as expected.

This section assumes you've already setup an Ubuntu server using the Deploy Rails on Ubuntu guide.

Our guide takes you through installing Passenger 5 but if you've installed it previous, you'll need to update to the latest version (5.0.24+) as it has been updated to work with Rails 5 and ActionCable.

ActionCable relies upon having a websocket server running and a pubsub server. For the pubsub connection, you can use either Redis or PostgreSQL as easy options to get started. It's recommended to use Redis for this because you're likely to be using it for background jobs anyways.

Install Redis

First we'll start by installing Redis server that will run locally on the server:

sudo apt-get install redis-server

Configure Your App

Next we'll modify our Rails app's configuration to use a mounted ActionCable server inside the routes.

Add the following to your config/routes.rb file at the top:

mount ActionCable.server => "/cable"

Modify your ActionCable Javascript to use that route in your app/assets/javascripts/channels/ file:

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

Set the allowed origin domains that you want to allow on websockets inside config/environments/production.rb. This should just be the domains your website runs on.

config.action_cable.allowed_request_origins = [""]

Finally, deploy your modified code

git commit -m "Configured ActionCable"
cap production deploy # Assuming you're using Capistrano

Configure Nginx & Passenger

Last but not least, you'll need to add a snippet to your Nginx config in /etc/nginx/sites-enabled/default:

server {
  listen 80;

  passenger_enabled on;
  rails_env production;
  root /home/deploy/your_app/current/public;

  location /cable {
    passenger_app_group_name your_app_websocket;
    passenger_force_max_concurrent_requests_per_process 0;

  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
    root html;

And restart Nginx!

sudo service nginx restart

Check out your site and you should have everything working! If you run into any issues, check your Rails and Nginx server logs for more information on the errors.

Coming soon!



Could you explain these two lines please:

passenger_app_group_name your_app_websocket;
passenger_force_max_concurrent_requests_per_process 0;


Roughly the first line tells Passenger to group app the websocket connections together for this app (in case you had multiple websockets apps on the same server) and the second line is saying that you can have an unlimited number of clients connect through websockets.

More info here: https://www.phusionpassenge...


how to get your_app_websocket?


Hey Chris nice article.

I am using Puma application server with nginx but the problem I am facing is that Action Cable works fine without ssl but I don't know what I have to do to get it work with SSL I get this message on browser.
WebSocket connection to 'wss://' failed: WebSocket is closed before the connection is established.

I have setup the config file in production.rb as well

config.action_cable.url = 'wss://'
config.action_cable.allowed_request_origins = [
'', '', '', ''

Still getting error. For SSL I have tried your article for Free SSL through let's encrypt. SSL working good but I don't understand this situation. Also for redis connection I have used redis labs service, I don't want extra redis burden on my server that's why.

Any Suggestions?


Login or create an account to join the conversation.