Apache HTTP Server (Apache2) adalah salah satu web server tertua dan paling banyak digunakan di dunia.
Apache dikenal fleksibel, stabil, dan memiliki banyak modul untuk menambah fitur (SSL, rewrite, proxy, dll).
Dokumen ini membahas instalasi, konfigurasi dasar, best practice, security hardening, serta setup SSL dengan Let's Encrypt.
sudo apt update
sudo apt install apache2 -y
sudo yum install httpd -y
sudo systemctl enable httpd
sudo systemctl start httpd
systemctl status apache2 # Debian/Ubuntu
systemctl status httpd # RHEL/CentOS
File konfigurasi utama:
/etc/apache2/apache2.conf
(Debian/Ubuntu)/etc/httpd/conf/httpd.conf
(RHEL/CentOS)/etc/apache2/sites-available/
dan /etc/apache2/sites-enabled/
Contoh konfigurasi virtual host sederhana:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/html
ErrorLog ${APACHE_LOG_DIR}/example_error.log
CustomLog ${APACHE_LOG_DIR}/example_access.log combined
</VirtualHost>
Aktifkan konfigurasi (Debian/Ubuntu):
sudo a2ensite example.com.conf
sudo systemctl reload apache2
Nonaktifkan informasi versi Apache
Edit /etc/apache2/conf-available/security.conf
:
ServerTokens Prod
ServerSignature Off
Batasi metode HTTP
<LimitExcept GET POST HEAD>
Deny from all
</LimitExcept>
Proteksi dari klikjacking & XSS
Header always set X-Frame-Options "SAMEORIGIN"
Header set X-Content-Type-Options nosniff
Header set X-XSS-Protection "1; mode=block"
Batasi ukuran upload
LimitRequestBody 10485760 # 10 MB
Nonaktifkan modul yang tidak diperlukan
sudo a2dismod autoindex
sudo a2dismod status
Gunakan user non-root
Pastikan Apache berjalan dengan user www-data
(Debian/Ubuntu) atau apache
(RHEL).
Debian/Ubuntu:
sudo apt install certbot python3-certbot-apache -y
RHEL/CentOS:
sudo yum install certbot python3-certbot-apache -y
sudo certbot --apache -d example.com -d www.example.com
Certbot akan otomatis mengedit konfigurasi Apache dan menambahkan SSL.
Cek konfigurasi:
sudo apachectl configtest
sudo systemctl reload apache2 # Debian/Ubuntu
sudo systemctl reload httpd # RHEL/CentOS
Certbot membuat cron job otomatis, bisa diuji dengan:
sudo certbot renew --dry-run
✅ Gunakan ServerTokens Prod
& ServerSignature Off
untuk menyembunyikan versi Apache.
✅ Pisahkan konfigurasi virtual host per domain.
✅ Gunakan ErrorLog
dan CustomLog
untuk monitoring.
✅ Nonaktifkan modul yang tidak digunakan.
✅ Gunakan firewall (UFW, iptables, atau security group) hanya untuk port 80 & 443.
✅ Aktifkan SSL (Let's Encrypt) dengan auto-renew.
✅ Gunakan mod_security
dan mod_evasive
untuk proteksi tambahan (WAF & DoS mitigation).
✅ Selalu update Apache2 untuk patch keamanan terbaru.
✅ Lakukan benchmark (ab
, wrk
) untuk tuning MaxRequestWorkers
, KeepAliveTimeout
, dll.