Rails ActionCable on Puma and Nginx not working on production after deploy via capistrano

I create web site using ActionCable via Rails on top of Puma and Nginx on production.

But after deploy to Production server seems like ActionCable is not working because of this problem.WebSocket connection to

WebSocket connection to 
'ws://' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET

This is my production.rb

config.action_cable.url = 'ws://'
config.web_socket_server_url = "ws://"
config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]
config.action_cable.disable_request_forgery_protection = true

This is my nginx.conf

upstream puma {
  server unix:///home/deploy/apps/app_name/shared/tmp/sockets/app_name-puma.sock;

server {
  listen 80 default_server deferred;
  # server_name;

  root /home/deploy/apps/app_name/current/public;
  access_log /home/deploy/apps/app_name/current/log/nginx.access.log;
  error_log /home/deploy/apps/app_name/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;

  location /cable {
    proxy_pass http://puma;
    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;

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;

My puma.rb

threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
port        ENV.fetch("PORT") { 3000 }
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
plugin :tmp_restart
environment ENV.fetch("RAILS_ENV") { "production" }
daemonize true
pidfile '/home/deploy/apps/app_name/shared/tmp/pids/'

How can i fix this and make ActionCable work on production?



Why you not set “server_name”?

And server name needs same as

server {
  listen 80 default_server deferred;
  # server_name;

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

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.

I have same issue! How do you solve this?