Configuring WebSocket via Action Cable


WebSocket is a protocol that allows bi-directional web communication between client and server, and Action Cable is the native Rails integration of this protocol. You can configure your application to communicate via Action Cable using the method below.

⚠️ AWS Classic Load Balancers do not support websockets natively. We recommend switching to one of Amazon’s newer load balancers.

Configuring your app for Action Cable

Action Cable runs as a “server” and needs to be configured in your config/routes.rb. You need to mount ActionCable.server to a local server path in your routes.rb.

For example, this mounts the server to the /cable path:

# Serve websocket cable requests in-process
mount ActionCable.server => '/cable'

Default application server configuration

If you’re using the default Cloud 66 application server for your Rails app (Passenger), will automatically configure your application to allow connections to the /cable endpoint. The endpoint will communicate via the same port as the rest of your application. You can change the name of this endpoint, but you will then need to modify your app’s NGINX settings using CustomConfig.

We will also configure Action Cable to use a separate connection pool to avoid it competing with normal HTTP connections.

Custom application server configuration

If you’re using a custom Rails application server we will add the required headers to NGINX to resolve your endpoints (including /cable). You will then need to configure your custom server to handle Action Cable.

Bear in mind that Action Cable (and WebSocket in general) tends to lead to a lot of persistent connections to your servers. You should configure and scale your application server to accommodate this.