【问题标题】:Sinatra + Thin + Nginx connect() failed (111: Connection refused) while connecting to upstreamSinatra + Thin + Nginx connect() 在连接到上游时失败(111:连接被拒绝)
【发布时间】:2022-01-18 01:56:36
【问题描述】:

我有一个在 Thin 上运行的 Sinatra 应用程序,使用 Nginx 作为反向代理并接收大量流量。 我的用户报告 502 错误并查看 Nginx 日志,我看到了很多这样的错误:

[warn] upstream server temporarily disabled while connecting to upstream
[error] connect() failed (111: Connection refused) while connecting to upstream

如果我查看 Sinatra 应用程序的日志,我没有发现任何错误。

我从以下内容开始:

--max-conns 15360 --max-persistent-conns 2048 --threaded start

我为 Ninx 设置了以下内容:

worker_processes  auto;
worker_rlimit_nofile 65535;

events {
    worker_connections  15360;
}

Sinatra 应用程序的主机文件:

server {
    server_name my_sinatra_app;

    #lots of bots try to find vulnerabilities in php sites
    location ~ \.php {
        return 404;
    }

    location / {
        proxy_pass http://localhost:6903;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_cache_bypass $http_upgrade;

        #increase buffers
        proxy_buffer_size          128k;
        proxy_buffers              4 256k;
        proxy_busy_buffers_size    256k;
    }

    listen 443 ssl; # managed by Certbot
    #...
    #SSL stuff
}

为什么会这样?流量过多?

解决办法是什么?我是否继续增加worker_connections--max-conns 直到错误停止?

htop 的输出似乎服务器可以处理更多:

有什么见解/建议吗?

编辑

虽然我在 Sinatra 日志或 systemctl status 输出中没有看到任何错误,但我确实注意到该服务从未运行很长时间,因此看起来瘦服务器经常崩溃。知道如何进一步调试吗?

【问题讨论】:

    标签: nginx sinatra nginx-reverse-proxy thin


    【解决方案1】:

    所以问题实际上出在 Thin 服务器上,由于某种原因,它每隔几分钟就会因 C++ 错误而崩溃,因此 Nginx 在尝试连接到 Thin 并失败时会抛出这些错误(因为 Thin 会崩溃/重新启动)。

    解决方案是用 Puma 替换 Thin,之后就没有问题了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-26
      • 2012-11-21
      • 2017-07-08
      • 2015-06-04
      • 1970-01-01
      • 2020-03-13
      • 2013-11-03
      • 2019-12-02
      相关资源
      最近更新 更多