How to Calculate and Tune Nginx’s Maximum Concurrent Connections

This article explains how Nginx’s maximum concurrent connections are determined by worker_processes and worker_connections, provides a sample configuration, discusses OS‑level limits such as file descriptors and kernel parameters, and offers practical tuning steps to scale Nginx to tens of thousands of connections.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
How to Calculate and Tune Nginx’s Maximum Concurrent Connections

Nginx does not have a fixed maximum concurrent connection limit; it is derived from the configuration and the underlying system resources. The commonly used theoretical formula is:

Maximum concurrent connections ≈ worker_processes × worker_connections

The key factors influencing this limit are:

worker_processes : Typically set to the number of CPU cores, determining how many worker processes Nginx runs.

worker_connections : The maximum number of connections a single worker can handle, constrained by the system’s ulimit -n (nofile) and the global file-max setting.

Example configuration:

worker_processes 4;

events {
    worker_connections 1024;
}

With the above settings, the theoretical maximum concurrent connections are 4 × 1024 = 4096 when Nginx serves static resources directly.

If Nginx operates as a reverse proxy, the effective number of concurrent users is usually about half of that value, roughly 2000, due to additional overhead.

Nginx uses an event‑driven, asynchronous, non‑blocking model, allowing each worker process to efficiently handle many connections. Consequently, the true ceiling is often dictated by operating‑system resources rather than Nginx itself.

Critical OS‑level constraints include the number of file descriptors, available memory, CPU capacity, and kernel network parameters (e.g., epoll/kqueue capabilities, TCP settings, and the maximum number of file handles). If system limits such as /proc/sys/fs/file-max or ulimit -n are not increased, Nginx cannot achieve the configured concurrency.

To scale Nginx’s concurrent handling capability to tens of thousands or even hundreds of thousands of connections, you should:

Raise the ulimit -n value and adjust /proc/sys/fs/file-max accordingly.

Tune kernel network parameters (e.g., net.core.somaxconn, net.ipv4.tcp_tw_reuse, etc.).

Optimize Nginx configuration (appropriate worker_processes and worker_connections values).

Deploy load balancers and consider horizontal scaling with multiple Nginx instances.

These steps enable Nginx to handle tens of thousands of concurrent connections reliably.

Nginx maximum concurrent connections diagram
Nginx maximum concurrent connections diagram
Nginx concurrency model illustration
Nginx concurrency model illustration
PerformanceConfigurationNginx
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.