I tried to deploy my Rails app which is contain Actioncable with Puma and Nginx.
So i got from the browser
WebSocket connection to 'ws://sub.domain.com/cable' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
Then when i check nginx error log i got this
This is my nginx config file
upstream puma {
server unix:///home/deploy/apps/app_repo/shared/tmp/sockets/app_repo-puma.sock;
}
server {
listen 80 default deferred;
server_name sub.domain.com;
root /home/deploy/apps/app_repo/current/public;
access_log /home/deploy/apps/app_repo/current/log/nginx.access.log;
error_log /home/deploy/apps/app_repo/current/log/nginx.error.log info;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
# enables WS support
location /cable {
proxy_pass http://puma;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 180;
}
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_read_timeout 180;
proxy_pass http://puma;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 20M;
keepalive_timeout 180;
}
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
daemonize true
pidfile 'home/deploy/apps/app_repo/shared/tmp/pids/puma.pid'
So how can i fix this and make Actioncable working well on prodeuction server?
Thanks you so much.