/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;
对静态资源生效)。