以下是Ubuntu LNMP環境的優化建議:
worker_processes
(建議設為CPU核心數)和worker_connections
(如1024)。HTTP/2
、keepalive
和靜態文件緩存(如expires 30d
)。keepalive_timeout
)。innodb_buffer_pool_size
(建議設為服務器內存的50%-70%)和max_connections
。query_cache_type=1
)并定期清理碎片(OPTIMIZE TABLE
)。OPcache
緩存編譯后的代碼,設置合理的內存限制(如opcache.memory_consumption=128
)。pm.max_children
等參數,匹配服務器資源。gzip
壓縮,減少傳輸數據量。net.core.somaxconn
、vm.swappiness
等參數,優化網絡和內存管理。noatime
選項,提升I/O性能。top
、htop
、Prometheus
等工具監控CPU、內存、磁盤I/O,及時調整配置。注:修改配置后需重啟對應服務(如sudo systemctl restart nginx
),建議先在測試環境驗證效果。
參考來源:[1,2,3,5,6,7,8,9,10,11,12,13,14]