要优化Ubuntu上的Apache2性能,可以采取以下几种方法:
sudo apt update && sudo apt upgrade
sudo a2dismod module_name
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
LoadModule deflate_module modules/mod_deflate.so
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript
LoadModule cache_module modules/mod_cache.so
LoadModule cache_disk_module modules/mod_disk_cache.so
CacheEnable disk /
CacheRoot "/var/cache/apache2"
CacheDirLevels 2
CacheDirLength 1
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
Proxy balancer://mycluster
BalancerMember http://backend1.example.com
BalancerMember http://backend2.example.com
/Proxy
ProxyPass / balancer://mycluster
LoadModule ssl_module modules/mod_ssl.so
SSLEngine on
SSLCertificateFile /etc/ssl/certs/your_domain.crt
SSLCertificateKeyFile /etc/ssl/private/your_domain.key
LoadModule status_module modules/mod_status.so
ExtendedStatus On
Location "/server-status"
SetHandler server-status
Order deny,allow
Deny from all
Allow from localhost
定期审查日志文件,合理设置日志级别,减少无用的日志输出,并定期清理过期日志文件。在进行任何系统优化之前,建议备份重要的数据,并谨慎操作,以免引起其他问题。