High‑concurrency Nginx deployments can exhaust the default per‑process file descriptor limit, triggering errors like too many open files and failed connection accepts. Raising the limit removes an artificial ceiling that can turn a traffic spike into dropped connections and upstream timeouts.
On Linux, sockets, log files, cache files, and many other resources are represented as file descriptors, and the kernel enforces a per‑process open-files limit (RLIMIT_NOFILE). When Nginx is started by systemd, the unit’s LimitNOFILE sets the maximum descriptors the master and worker processes can inherit. The worker_rlimit_nofile directive can request a specific limit for workers, but it cannot exceed the service limit or the kernel’s own maximum.
Reverse proxies often consume multiple descriptors per request (client + upstream), and extra headroom is needed for listening sockets, log files, open file caches, and keepalive connections. Values that exceed the kernel per‑process ceiling (exposed via /proc/sys/fs/nr_open/) can prevent nginx.service from starting, while values that are too low cap effective worker_connections regardless of CPU capacity. A systemd unit override is required for service-managed deployments because login-shell limits in /etc/security/limits.conf do not apply to systemd services.
Steps to increase file descriptor limits for Nginx:
- Pick a target open-files limit for nginx.
65535 is a common starting point for busy sites; raise only when monitoring shows consistent near-limit usage. Keep worker_connections comfortably below the per-worker limit to leave room for logs, caches, and upstream sockets.
- Check the kernel per-process open-files ceiling.
$ cat /proc/sys/fs/nr_open 1048576
LimitNOFILE values above this ceiling cannot be applied.
- Check the current LimitNOFILE value for nginx.service.
$ sudo systemctl show nginx -p LimitNOFILE LimitNOFILE=1024
Some distributions ship a higher default (often 65536) in the vendor unit file.
- Open a systemd drop-in override for nginx.
$ sudo systemctl edit nginx
The editor typically opens /etc/systemd/system/nginx.service.d/override.conf.
- Set LimitNOFILE under a Service section in the drop-in file.
[Service] LimitNOFILE=65535
A value above /proc/sys/fs/nr_open/ can prevent nginx.service from starting (often reported as Failed at step LIMITS).
- Reload systemd unit files.
$ sudo systemctl daemon-reload
No output indicates success.
- Restart nginx to apply the new unit limits.
$ sudo systemctl restart nginx
A restart closes existing connections; schedule for low-traffic windows when possible.
- Confirm nginx.service is active.
$ sudo systemctl status nginx ● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2025-12-08 09:41:12 UTC; 8min ago Docs: man:nginx(8) ##### snipped ##### - Edit /etc/nginx/nginx.conf/.
$ sudoedit /etc/nginx/nginx.conf
Additional configuration may be included from /etc/nginx/conf.d/ or /etc/nginx/sites-enabled/ depending on the distribution.
- Set worker_rlimit_nofile in the main context to match the service limit.
worker_processes auto; worker_rlimit_nofile 65535;
Keep worker_rlimit_nofile at or below the LimitNOFILE value set in systemd.
- Set worker_connections in the events block.
events { worker_connections 16384; }Reverse-proxying may consume at least two descriptors per active request (client + upstream).
- Test the nginx configuration syntax.
$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
- Reload nginx to apply configuration changes.
$ sudo systemctl reload nginx
A reload rereads configuration without a full service restart.
- Get the nginx master process PID.
$ pgrep -xo nginx 1234
- Verify the process open-files limit.
$ sudo grep -i "Max open files" /proc/1234/limits Max open files 65535 65535 files
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
