以下是Debian上优化Nginx的关键方法:
worker_processes设为CPU核心数。worker_connections调至65535(需配合ulimit -n)。events { use epoll; }。expires 30d; + add_header Cache-Control。proxy_cache配置缓存目录及有效期。gzip on; + gzip_types指定压缩类型。sendfile on; + tcp_nopush on;减少数据拷贝。listen 443 ssl http2;。keepalive_timeout 60; + client_body_timeout 12;。limit_conn_zone + limit_conn。ssl_ciphers HIGH:!aNULL:!MD5; + ssl_protocols TLSv1.2 TLSv1.3;。/etc/sysctl.conf:增大net.core.somaxconn等参数。apt autoremove。修改后需重启Nginx并测试性能,可通过top、htop监控资源使用情况。