提高CentOS LNMP(Linux, Nginx, MySQL, PHP)的訪問速度可以從多個方面進行優化。以下是一些關鍵的優化步驟和建議:
worker_processes
,通常設置為CPU核心數。worker_connections
默認是1024,可以增加到2048或更高。gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 30d;
add_header Cache-Control "public, no-transform";
}
;zend_extension=opcache.so
opcache.enable=1
opcache.memory_consumption=64
opcache.max_accelerated_files=4000
opcache.validate_timestamps=1
pm.max_children
、pm.start_servers
、pm.min_spare_servers
、pm.max_spare_servers
等參數,根據服務器內存和性能進行調整。pm = dynamic
pm.max_children = 25
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
[mysqld]
innodb_buffer_pool_size = 1G
query_cache_size = 64M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
tc
命令等工具,合理分配網絡帶寬。通過上述方法,可以有效地提升CentOS LNMP網站的訪問速度和整體性能。