简体   繁体   English

ActionCable + Nginx + Puma和java.io.EOFException

[英]ActionCable + Nginx + Puma and java.io.EOFException

I'm trying to connect to an ActionCable websocket and everything works fine running locally with just Puma and without nginx. 我正在尝试连接到ActionCable网络套接字,并且仅使用Puma而不使用nginx即可在本地正常运行。

However, when I try to do the exact same thing on my staging environment, the connection is immediately closing after connecting. 但是,当我尝试在暂存环境中执行完全相同的操作时,连接将在连接后立即关闭。 I am able to get the downstream welcome messages and maybe a ping. 能够得到下游欢迎的消息,也许平。

However, the connection abruptly closes without any of the onClose callbacks so my guess is nginx is not letting the connection persist. 但是,该连接突然关闭而没有任何onClose回调,因此我的猜测是nginx不会让该连接持久。

Here is my sites nginx configuration. 这是我的站点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;
}

I also found this error in nginx error logs: 我还在nginx错误日志中发现了此错误:

2019/02/11 21:08:35 [error] 10233#10233: *2 recv() failed (104: Connection reset by peer) while proxying upgraded connection, client: xxxx, server: localhost, request: "GET /cable/ HTTP/1.1", upstream: " http://unix:/home/deploy/wr-api/shared/tmp/sockets/puma.sock:/cable/ ", host: "xxxx" 2019/02/11 21:08:35 [错误] 10233#10233:* 2 recv()失败(104:对等方重置连接),同时代理升级的连接,客户端:xxxx,服务器:localhost,请求:“ GET / cable / HTTP / 1.1”,上游:“ http:// unix:/home/deploy/wr-api/shared/tmp/sockets/puma.sock:/ cable / ”,主机:“ xxxx”

So after some time, we noticed that the staging environment cable.yml had this value for url: 因此,一段时间后,我们注意到登台环境cable.yml的url具有以下值:

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

Removing that value and all other values except for adapter: staging fixed it for us. 除去该值和除adapter: staging以外的所有其他值adapter: staging为我们修复了该值。

New cable.yml staging config: 新的cable.yml登台配置:

staging:
  adapter: redis

Working! 工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM