nginx resource_error ai_generated true

nginx: [alert] socket() failed (24: Too many open files)

ID: nginx/open-too-many-files

Also available as: JSON · Markdown
92%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active

Root Cause

nginx process hit the OS file descriptor limit. Each connection uses at least 2 FDs (client + upstream). Proxy doubles this.

generic

Workarounds

  1. 92% success Set worker_rlimit_nofile in nginx.conf
    worker_rlimit_nofile 65536;  # in main context of nginx.conf; sets RLIMIT_NOFILE for worker processes

    Sources: https://nginx.org/en/docs/http/ngx_http_core_module.html

  2. 90% success Increase limits in systemd service unit
    In /etc/systemd/system/nginx.service.d/override.conf: [Service] LimitNOFILE=65536; then: systemctl daemon-reload && systemctl restart nginx
  3. 85% success Set system-wide limits in /etc/security/limits.conf
    * soft nofile 65536
    * hard nofile 65536
    # Also check: sysctl fs.file-max

Dead Ends

Common approaches that don't work:

  1. Restart nginx to temporarily fix the issue 85% fail

    Restarting reclaims FDs but the limit is hit again under the same load. Must increase the limit.

  2. Only set ulimit in the shell before starting nginx 80% fail

    Shell ulimit does not persist across service restarts. Must configure in systemd unit or nginx.conf.