back to index

A Few Nginx Tuning Knobs

A handful of Nginx config knobs worth knowing: workers, file descriptors, TCP options.

published Feb 15, 2019 tags #linux #nginx

~/posts/nginx-tuning $ cat post.md

/ LANG EN / 中文
/ THEME / /

Scope

Nginx is modular, so you “tune” it by tweaking a few specific modules. “Tuning” is a strong word — most of this is telling Nginx what your project cares about.

This builds on the config from the earlier post, Reverse-Proxying a Node Service with Nginx.

Globals

Two global settings worth attention:

  • worker_processes auto;
  • worker_rlimit_nofile 4864;

worker_processes is the worker count. Keep it on auto and let Nginx pick based on CPU cores.

worker_rlimit_nofile caps how many files a worker can hold open. You can raise it up to the system limit. 4864 was the cap on my Mac. If a project opens a lot of files (a reverse-proxy fronting many small asset files, for example), this one is worth bumping.

HTTP block

There’s a lot in the HTTP block, but most of it adjusts behavior more than it adjusts performance. Two that come up most:

  • tcp_nopush on;
  • tcp_nodelay on;

tcp_nopush tells Nginx to bundle response headers into a single packet before sending. Leave it on most of the time. tcp_nodelay disables buffering and sends packets immediately. Turn this on only when the project really needs low-latency.

back to index