提高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网站的访问速度和整体性能。