Mengaktifkan GZIP compression di Apache

Cara mengaktifkan GZIP compression di Apache. Agar setiap virtual host Apache mampu mengkompres data dengan metode GZIP (mod_deflate) tambahkan baris berikut ke dalam konfigurasi httpd.conf

Umumnya lokasi file konfigurasi Apache adalah:

  • Linux Centos: /etc/httpd/conf/httpd.conf
  • Linux Debian/Ubuntu: /etc/apache2/httpd.conf

Berikut kodenya

<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar|apk|7z|so|iso|app|doc|ppt|xls|wps|dll)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm|mpeg|asf|wmv|wma|3gp|mkv|flv|f4v|webm|mpg|acc)$ no-gzip dont-vary
    AddOutputFilterByType DEFLATE text/*
    AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript application/javascript application/x-javascript
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

Simpan dan restart Apache.

Add a comment