On Unix-like systems, every open file, socket and pipe uses a file descriptor. The file descriptor limit is the maximum number a process, user or whole system may have open at once. Hitting it gives the error Too many open files (EMFILE).
Why it matters
Each client connection to a web server or proxy consumes at least one descriptor, and a proxy uses two (client and upstream). A busy server can hit a default of 1024 and start refusing connections while CPU is idle, which looks like a mysterious outage. Limits exist at several levels: per process, per user and system-wide.
Example
Inspect and raise the limit for a service:
ulimit -n # current shell limit
cat /proc/$(pidof nginx)/limits # limit of a running process
For a systemd service, set it in the unit file, then reload and restart:
[Service]
LimitNOFILE=65536
Nginx also has worker_rlimit_nofile. Look for Too many open files in the error log to confirm.
Common mistakes
- Editing
/etc/security/limits.conffor a service that systemd starts, which ignores it. - Raising the limit while a descriptor leak is the real cause, which only delays the crash.
- Forgetting the system-wide
fs.file-maxceiling.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.