Ruby on rails 生产上的ActionCable:WebSocket握手期间出错:意外响应代码:404

Ruby on rails 生产上的ActionCable:WebSocket握手期间出错:意外响应代码:404,ruby-on-rails,nginx,websocket,actioncable,Ruby On Rails,Nginx,Websocket,Actioncable,在开发模式下,在我的本地计算机上一切正常,但在生产服务器上尝试使用ActionCable时,我得到: WebSocket connection to 'wss://example.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 404 我忘了什么吗?我在Nginx上运行Puma /etc/nginx/nginx.conf: user www-data; worker_processes

在开发模式下,在我的本地计算机上一切正常,但在生产服务器上尝试使用ActionCable时,我得到:

WebSocket connection to 'wss://example.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 404
我忘了什么吗?我在Nginx上运行Puma

/etc/nginx/nginx.conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    server_tokens off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
/etc/nginx/sites enabled/example.com:

upstream myapp_unicorn {
  server localhost:9393;
}


server {
    listen 80;
    server_name example.com;
    return 301 https://example.com/$request_uri;    
}

server {
  server_name example.com;

  listen x.x.x.x:443 ssl http2; # ip censored for SO
  ssl_certificate /etc/letsencrypt/live/example.com-0004/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/example.com-0004/privkey.pem; # managed by Certbot
  include snippets/ssl-params.conf;


  client_max_body_size 50M;
  root /home/myapp/app/myapp/production/current/public;

  location = /webdav { return 404; log_not_found off; }
  location = /apple-touch-icon-120x120.png { return 404; log_not_found off; }
  location = /apple-touch-icon-120x120-precomposed.png { return 404; log_not_found off; }

  location ~ ^/(assets|uploads|images|javascripts|stylesheets|system)/  {
    expires max;
    break;
  }

  location /doc/api {
    alias /home/myapp/app/myapp/production/current/doc/api/;
    try_files $uri $uri/ =404;
  }

  location @myapp {
    proxy_read_timeout 3000;
    proxy_connect_timeout 3000;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_redirect off;
    proxy_pass http://myapp_unicorn;
  }
}

注意:
example.com
仅适用于本帖。在我的配置中,我使用正确的域。

尝试在config/production.rb中设置配置

  # Mount Action Cable outside main process or domain
  config.action_cable.url = 'wss://example.com/cable'
  config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

没有帮助。