ActionCable + Nginx + Puma 和 java.io.EOFException

ActionCable + Nginx + Puma and java.io.EOFException

我正在尝试连接到 ActionCable websocket,一切正常 运行 在本地仅使用 Puma 而没有使用 nginx。

但是,当我尝试在暂存环境中执行完全相同的操作时,连接在连接后立即关闭。我 能够收到下游的欢迎消息,也许还有 ping。

但是,连接在没有任何 onClose 回调的情况下突然关闭,所以我猜 nginx 不会让连接持续存在。

这是我的网站 nginx 配置。

upstream app {
  # Path to Puma SOCK file, as defined previously
  server unix:/home/deploy/my-app/shared/tmp/sockets/puma.sock fail_timeout=60;
  keepalive 60;
}

server {
        listen 80;
        server_name localhost;
#       websocket_pass websocket;

        root /home/deploy/my-app/current/public;

        try_files $uri/index.html $uri @app;

        location @app {
          proxy_pass http://app;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_redirect off;
        }

        #location / {
        #        proxy_set_header X-Forwarded-Proto $scheme;
        #        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        #        proxy_set_header X-Real-IP $remote_addr;
        #        proxy_set_header Host $host;
        #        proxy_redirect off;
        #        proxy_http_version 1.1;
        #        proxy_set_header Connection '';
        #        proxy_pass http://app;
        #}

        location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
          gzip_static on;
          expires max;
          add_header Cache-Control public;
        }

        location /cable {
          proxy_pass http://app;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "Upgrade";
        }

        error_page 500 502 503 504 /500.html;
        client_max_body_size 4G;
        keepalive_timeout 10;
}

我在nginx错误日志中也发现了这个错误:

2019/02/11 21:08:35 [error] 10233#10233: *2 recv() failed (104: Connection reset by peer) while proxying upgraded connection, client: x.x.x.x, server: localhost, request: "GET /cable/ HTTP/1.1", upstream: "http://unix:/home/deploy/wr-api/shared/tmp/sockets/puma.sock:/cable/", host: "x.x.x.x"

一段时间后,我们注意到暂存环境 cable.yml 具有 url 的值:

url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>

删除该值和除 adapter: staging 之外的所有其他值已为我们修复它。

新 cable.yml 暂存配置:

staging:
  adapter: redis

工作中!