在Puma和nginx上运行的Rails应用程序每隔几个小时就会与Bad Gateway一起死亡

Cat*_*ish 6 ruby-on-rails nginx puma

我有一个我刚刚部署到Digital Ocean的rails应用程序,它在Puma和Nginx上运行.

最终返回的是一个糟糕的网关,这就是error.log中的内容

2014/09/09 22:23:06 [error] 5729#0: *3059 connect() to unix:///var/www/mysite/mysite_app.sock failed (111: Connection refused) while connecting to upstream, client: 67.5.19.192, server: mysite.com, request: "GET / HTTP/1.1", upstream: "http://unix:///var/www/mysite/mysite_app.sock:/", host: "mysite.com"
Run Code Online (Sandbox Code Playgroud)

为了解决它,我只是重启puma,它似乎工作.

我怎样才能调试它以找出它为什么一直在死?

这是我的nginx配置:

upstream mysite {
                server unix:///var/www/mysite/mysite_app.sock;
        }
        server {
                listen 80;
                server_name mysite.com;
                root /var/www/mysite/current/public;
        client_max_body_size 20M;

                location / {
                        proxy_pass http://mysite; # match the name of upstream directive which is defined above
                        proxy_set_header Host $host;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                }
                location ~* ^/assets/ {
                        # Per RFC2616 - 1 year maximum expiry
                        expires 1y;
                        add_header Cache-Control public;

                        # Some browsers still send conditional-GET requests if there's a
                        # Last-Modified header or an ETag header even if they haven't
                        # reached the expiry date sent in the Expires header.
                        add_header Last-Modified "";
                        add_header ETag "";
                        break;
                }
        }
Run Code Online (Sandbox Code Playgroud)

编辑

这可能是由于内存耗尽造成的吗?

这是我当前的记忆状态,但是随着我经常运行这个命令,可用内存量下降,一旦我重启puma,它就会跳回到150.

$ free -m
             total       used       free     shared    buffers     cached
Mem:           490        440         50          0         17         84
-/+ buffers/cache:        338        151
Swap:            0          0          0
Run Code Online (Sandbox Code Playgroud)

Cat*_*ish 4

看起来这实际上是 ruby​​ 2.1(特别是我正在使用 2.1.2)及其垃圾收集的问题。

像这样的谷歌搜索似乎有很多不同的线程http://bit.ly/1s2vBC0

这是有关该问题的 ruby​​ 错误票:https ://bugs.ruby-lang.org/issues/9607