要優化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
定期審查日志文件,合理設置日志級別,減少無用的日志輸出,并定期清理過期日志文件。在進行任何系統優化之前,建議備份重要的數據,并謹慎操作,以免引起其他問題。