Dustin's Dev Notes

Nginx Performance Tuning: From Defaults to 100K Connections

Out of the box, Nginx can handle about 10K concurrent connections on a typical server. With proper tuning, we pushed it to 100K+ on a 4-core VPS. Here's how.

Worker Processes and Connections

worker_processes auto;
events {
    worker_connections 65535;
    multi_accept on;
    use epoll;
}

Kernel Tuning

The OS-level limits are often the real bottleneck:

# /etc/sysctl.d/99-nginx.conf
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_tw_reuse = 1
fs.file-max = 2097152

Proxy Buffer Settings

For API gateway workloads, these settings made the biggest difference:

proxy_buffering on;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;