【问题标题】:Nginx configuration resulting in too many connectionsNginx 配置导致连接过多
【发布时间】:2014-11-19 11:25:49
【问题描述】:

在尝试实现upload progress module 时,以下服务器配置导致打开文件过多错误

2014/11/19 12:10:34 [alert] 31761#0: *1010 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: xxx, request: "GET /documents/15/edit HTTP/1.0", upstream: "http://127.0.0.1:80/documents/15/edit", host: "127.0.0.1"
2014/11/19 12:10:34 [crit] 31761#0: *1010 open() "/usr/share/nginx/html/50x.html" failed (24: Too many open files), client: 127.0.0.1, server: xxx, request: "GET /documents/15/edit HTTP/1.0", upstream: "http://127.0.0.1:80/documents/15/edit", host: "127.0.0.1"

以下是产生冲突的服务器块的相关部分 乘客启用; rails_env 开发; 根 /home/user/app/current/public;

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    location / {
        # proxy to upstream server
        proxy_pass http://127.0.0.1;
        proxy_redirect default;

        # track uploads in the 'proxied' zone
        # remember connections for 30s after they finished
        track_uploads proxied 30s;
    }

    location ^~ /progress {
        # report uploads tracked in the 'proxied' zone
        report_uploads proxied;
    }

作为 nginx 的相对 n00b,我不明白这是在哪里产生了太多文件错误。我假设错误页面仅针对 500-504 服务器错误...

【问题讨论】:

    标签: nginx ruby-on-rails-3.2 passenger


    【解决方案1】:

    首先检查并增加root shell中的打开文件限制(系统范围,通常为1024):

    # ulimit -n
    # ulimit -n 16384
    

    然后你可以增加nginx的打开文件限制(主要上下文,nginx.conf的顶部):

    worker_rlimit_nofile 16384
    

    然后重启nginx)

    如果这没有帮助,请查看更详细的解决方案,例如

    Nginx: 24: Too Many Open Files Error And Solution

    【讨论】:

    • 似乎与在事件级别定义的worker_connections 有某种关系。因为我得到了8192 worker_connections are not enough 这个数字,我通过反复试验插入,但导致too many files 或worker_conncetions 错误不足。该链接建议系统范围的限制。我可以尝试一下,但是硬限制和软限制之间是否存在关系?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-11
    相关资源
    最近更新 更多