/etc/sysctl.conf
,設置net.ipv4.tcp_max_tw_buckets=6000
、net.ipv4.tcp_tw_reuse=1
、net.core.somaxconn=65535
等,減少連接占用。/etc/sysctl.conf
中設置fs.file-max=10000000
,并在/etc/security/limits.conf
中配置nofile
限制。worker_processes auto;
,并根據CPU核心數調整worker_connections
(建議1024-4096)。sendfile on;
、tcp_nopush on;
,提升文件傳輸效率。expires
指令緩存圖片、CSS等靜態文件,減少后端請求。http2
,利用多路復用降低延遲。EECDH+AESGCM
)。worker_rlimit_nofile
限制文件描述符使用,或使用cgroups限制CPU/內存占用。autoindex
等非必要模塊,減少內存占用。top
、htop
或nginx-module-vts
監控資源使用情況,調整配置參數。access_log off;
對靜態資源生效)。