【问题标题】:Rails app running on puma and nginx keeps dying every few hours with Bad Gateway在 puma 和 nginx 上运行的 Rails 应用程序每隔几个小时就会因 Bad Gateway 而死机
【发布时间】:2014-10-02 07:28:50
【问题描述】:

我有一个刚刚部署到 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"

要修复它,我只需重新启动 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;
                }
        }

编辑

这可能是由于内存不足造成的吗?

这是我当前的内存状态,但是当我经常运行此命令时,可用内存量会下降,一旦我重新启动 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

【问题讨论】:

    标签: ruby-on-rails nginx puma


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      内存不足可能是问题,但您最好查看 puma 和 rails 日志,而不仅仅是 nginx。在应用程序文件夹中:

      tail -f log/puma*
      tail -f log/production.log
      

      【讨论】:

      • 在 production.log 文件中没有任何内容对我产生影响。我没有找到 puma 日志文件。
      【解决方案3】:

      我也遇到过类似的问题,但我注意到 2.1.3 现已发布并专门讨论内存问题:

      https://www.ruby-lang.org/en/news/2014/09/19/ruby-2-1-3-is-released/

      我现在就去试试!

      【讨论】:

        猜你喜欢
        • 2015-10-14
        • 2020-04-22
        • 2014-11-27
        • 2015-05-18
        • 1970-01-01
        • 2018-12-30
        • 2015-11-20
        • 2016-09-14
        • 2020-12-14
        相关资源
        最近更新 更多