以下是Debian Nginx的优化策略:
worker_processes
设为CPU核心数。worker_connections
增大至1024+(需结合系统限制)。epoll
事件模型(Linux)。sendfile on
减少数据拷贝。tcp_nopush on
优化TCP包发送。expires 30d
缓存头。proxy_cache
缓存后端响应。gzip on
压缩(gzip_comp_level 6
)。http2 on
)。server_tokens off
。limit_conn_zone
+limit_conn
。worker_rlimit_nofile
增加文件描述符限制。net.ipv4.tcp_tw_reuse=1
)。top/htop
监控资源占用。apt autoremove
。注意:修改配置后需执行nginx -s reload
生效,重大变更前建议备份配置并测试。
参考来源: