Berikut adalah penjelasan lengkap tentang bagaimana mempercepat Apache2 di Ubuntu, file yang diubah, dan langkah-langkah optimasinya:
/etc/apache2/apache2.conf
MPM
(Multi-Processing Modules) dengan beban server Anda. Jika menggunakan MPM Prefork, tambahkan atau ubah konfigurasi berikut:<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 3000
</IfModule>
<IfModule mpm_event_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 300
MaxConnectionsPerChild 10000
</IfModule>
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 2
/etc/apache2/mods-enabled/
mod_deflate
:sudo a2enmod deflate
sudo systemctl restart apache2
/etc/apache2/conf-available/deflate.conf
:<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE application/javascript application/json
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
sudo systemctl restart apache2
/etc/apache2/sites-available/000-default.conf
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
</IfModule>
mod_expires
dan mod_headers
jika belum aktif:sudo a2enmod expires
sudo a2enmod headers
sudo systemctl restart apache2
/etc/apache2/sites-available/your-site.conf
sudo a2enmod http2
sudo systemctl restart apache2
Protocols h2 http/1.1
ke konfigurasi virtual host:<VirtualHost *:443>
Protocols h2 http/1.1
ServerName yourdomain.com
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/ssl/certs/your_cert.crt
SSLCertificateKeyFile /etc/ssl/private/your_cert.key
...
</VirtualHost>
/etc/sysctl.conf
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_fin_timeout = 15
sudo sysctl -p
/etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
sudo a2dismod status
sudo a2dismod autoindex
rewrite
headers
deflate
http2
expires
sudo apache2ctl configtest
sudo systemctl restart apache2
top
, htop
, atau Apache Bench
(ab) untuk melihat performa server.