Busy Nginx servers can hit the open-files ceiling long before CPU or bandwidth becomes the real bottleneck. Raising the file descriptor limit gives the workers enough headroom for client sockets, upstream sockets, log files, and cache files so traffic spikes do not collapse into too many open files errors.
In Nginx, worker_connections sets the per-worker connection ceiling, but the official documentation notes that this count includes proxied upstream connections and still cannot exceed the current open-files limit. The worker_rlimit_nofile directive raises the worker-side RLIMIT_NOFILE value, while systemd LimitNOFILE controls the maximum limit the service can inherit when nginx starts.
Choose a target that matches your traffic pattern instead of jumping straight to the kernel maximum. Keep the value at or below /proc/sys/fs/nr_open/, leave headroom above worker_connections for logs and upstream sockets, and expect to restart nginx after changing the service limit because the new inherited ceiling applies only to newly started processes.
Related: How to tune worker_connections in Nginx
Related: How to improve Nginx performance
65535 is a common starting point for busy sites, but the right value depends on concurrency, keepalive usage, upstream proxying, and how many other files each worker keeps open.
$ cat /proc/sys/fs/nr_open 1048576
LimitNOFILE and worker_rlimit_nofile cannot exceed this kernel limit.
$ sudo systemctl show -p LimitNOFILE nginx LimitNOFILE=1024
This is the maximum limit the service can pass to newly started nginx processes; if it already exceeds your target, you only need to align worker_rlimit_nofile with it.
$ sudo nginx -T 2>/dev/null | grep -E '^[[:space:]]*(worker_processes|worker_rlimit_nofile|worker_connections)[[:space:]]'
worker_processes auto;
worker_connections 1024;
If no worker_rlimit_nofile line appears, the workers are using the inherited process limit.
$ sudo systemctl edit --drop-in=limits.conf nginx
This writes /etc/systemd/system/nginx.service.d/limits.conf and reloads the unit definition automatically when you save and exit.
[Service] LimitNOFILE=65535
A value above /proc/sys/fs/nr_open/ can prevent nginx.service from starting.
$ sudoedit /etc/nginx/nginx.conf
Most Linux packages keep the main file here and include additional snippets from directories such as /etc/nginx/conf.d/ and sometimes /etc/nginx/sites-enabled/.
worker_processes auto; worker_rlimit_nofile 65535;
Keep worker_rlimit_nofile at or below the service LimitNOFILE value.
events {
worker_connections 16384;
}
Nginx counts proxied upstream sockets too, so the open-files limit must leave room above the raw client connection count.
$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Related: How to test Nginx configuration
$ sudo systemctl restart nginx
A restart replaces the running master and worker processes, so plan this change for a maintenance window on busy hosts.
Related: How to manage the Nginx service
$ sudo systemctl show -p ActiveState -p MainPID -p LimitNOFILE nginx ActiveState=active MainPID=1741 LimitNOFILE=65535
Related: How to manage the Nginx service
$ sudo grep -i "Max open files" /proc/$(sudo systemctl show --value -p MainPID nginx)/limits Max open files 65535 65535 files