在Ubuntu上优化Apache脚本执行可从以下方面入手:
sudo apt install php-opcache
/etc/php/7.x/apache2/php.ini
中启用opcache.enable=1
,并设置内存大小等参数。KeepAlive
复用TCP连接,减少连接建立开销:KeepAlive On
,并设置合理的MaxKeepAliveRequests
和KeepAliveTimeout
。MaxClients
(或MaxRequestWorkers
)参数,根据服务器资源调整并发连接数上限。mod_deflate
压缩响应内容(如HTML、CSS、JS),减少传输数据量。mod_expires
和mod_headers
设置静态资源缓存策略,降低重复请求频率。memory_limit
和max_execution_time
,避免脚本因资源不足中断。vm.swappiness
)。修改配置后需重启Apache服务生效:sudo systemctl restart apache2
[1,2,3,4,6,7,8,9,10,11]。