Debian系统下Nginx资源占用高,可通过以下方式优化:
worker_processes设为CPU核心数。worker_connections(默认1024,可根据内存调整)。epoll事件模型(Linux默认支持)。keepalive并缩短超时时间(如keepalive_timeout 15s)。proxy_cache或sendfile)。gzip on)减少传输数据量。client_body_buffer_size 8k)。client_max_body_size)。apt autoremove)。vm.swappiness=10)。top/htop监控资源,定位异常进程。修改配置前建议备份文件,修改后使用nginx -t测试语法,再systemctl reload nginx重载配置。