Master Nginx Performance: Tuning Workers, Caching, Gzip, and System Parameters
This guide details comprehensive Nginx performance optimization, covering worker process sizing, CPU affinity, file descriptor limits, event model settings, HTTP directives, fastcgi parameters, gzip compression, expires caching, anti‑hotlinking, and essential Linux kernel tweaks for high‑traffic servers.
1. Worker Processes and CPU Affinity
Set worker_processes to the number of CPU cores or twice that value; determine core count with top -1 or grep ^processor /proc/cpuinfo | wc -l. Example: worker_processes 4; Configure CPU affinity to bind workers to specific cores, e.g. for 4 cores: worker_cpu_affinity 0001 0010 0100 1000; For 8 cores, use eight affinity masks accordingly. Limit workers to a maximum of 8 for stability.
2. File Descriptor Limits
Increase the maximum open files per worker with: worker_rlimit_nofile 65535; Adjust system limits in /etc/security/limits.conf:
* soft nofile 65535
* hard nofile 65535Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
