

As a caching server, NGINX behaves like a web server for cached responses and like a proxy server if the cache is empty or expired. When it acts as a proxy server, NGINX uses one FD each for the connection to the client and upstream server, and potentially a third FD for the file used to store the server’s response temporarily.

When NGINX acts as a web server, it uses one FD for the client connection and one FD per served file, for a minimum of two FDs per client (but most web pages are built from many files). Here’s why more FDs are needed: each connection from an NGINX worker process to a client or upstream server consumes an FD. The fix is to set that value with the worker_rlimit_nofile directive in the main configuration context. The common configuration mistake is not increasing the limit on FDs to at least twice the value of worker_connections. Indeed, the default nf file we distribute with NGINX Open Source binaries and NGINX Plus increases it to 1024. In modern UNIX distributions, the default limit is 1024.įor all but the smallest NGINX deployments, a limit of 512 connections per worker is probably too small. But it’s important to keep in mind that ultimately there is another limit on the number of simultaneous connections per worker: the operating system limit on the maximum number of file descriptors (FDs) allocated to each process. All types of connections (for example, connections with proxied servers) count against the maximum, not just client connections. The worker_connections directive sets the maximum number of simultaneous connections that a NGINX worker process can have open (the default is 512). Mistake 1: Not Enough File Descriptors per Worker

Forgetting how directive inheritance works.

