🟢 STATUS PORTAL: LOKASI: YOGYAKARTA, INDONESIA
← [KEMBALI KE INDEKS REKAYASA BLOG] MODE BACA: INDEPEDENT_READER
📅 TANGGAL: 12 Mei 2026 ⏱ ESTIMASI BACA: 6 Min Read
WordPressSpeed

Konfigurasi Nginx FastCGI Cache untuk Melipatgandakan Kecepatan WordPress pada VPS Hemat

[SHARE_URL] ──►

Pengantar: Memulai dari Core Server

Banyak pengembang WordPress mengandalkan plugin cache berat seperti WP Rocket atau W3 Total Cache untuk mempercepat situs web mereka. Padahal, setiap kali request menyentuh kode PHP, server harus mengeksekusi script, menghubungkan database SQL, lalu menyusun HTML. Ini membuang waktu & CPU resource.

Dengan Nginx FastCGI Cache, halaman HTML yang di-generate dinamis oleh PHP akan disimpan langsung di level memory server. Request berikutnya tidak akan memicu PHP-FPM, melainkan langsung disajikan instan oleh Nginx.


Langkah 1: Mendefinisikan Cache Zone pada nginx.conf

Buka konfigurasi server blok utama Anda melalui terminal SSH:

SHELL SOURCE VIEWPORT // LANG: BASH
$ nano /etc/nginx/nginx.conf

Tambahkan baris parameter berikut di dalam blok http { ... }:

SHELL SOURCE VIEWPORT // LANG: NGINX
fastcgi_cache_path /var/nginx/cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;

Langkah 2: Mengkonfigurasi Server Block Virtual Host

Pada file server block website Anda, tentukan pengecualian cookie (misalnya menghindari cache halaman login admin atau checkout keranjang WooCommerce):

SHELL SOURCE VIEWPORT // LANG: NGINX
set $skip_cache 0;

# Jangan cache halaman admin WordPress
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
    set $skip_cache 1;
}

# Jangan cache user yang sedang login
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
    set $skip_cache 1;
}

Lalu arahkan block PHP handler Anda menuju key_zone yang didefinisikan:

SHELL SOURCE VIEWPORT // LANG: NGINX
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/run/php/php8.2-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    
    fastcgi_cache WORDPRESS;
    fastcgi_cache_valid 200 301 302 1h;
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;
    
    add_header X-FastCGI-Cache $upstream_cache_status;
}

Langkah 3: Verifikasi Status Handshake

Wipe/restart Nginx daemon Anda untuk menerapkan perubahan:

SHELL SOURCE VIEWPORT // LANG: BASH
$ nginx -t && systemctl restart nginx

Gunakan perintah curl untuk melihat HTTP header:

SHELL SOURCE VIEWPORT // LANG: BASH
$ curl -I https://portofolio.web.id

Sistem akan memberikan respon:

SHELL SOURCE VIEWPORT // LANG: HTTP
HTTP/2 200
content-type: text/html; charset=UTF-8
x-fastcgi-cache: HIT

Status HIT menandakan bahwa loading aset halaman berjalan instan secepat static minimal HTML!

// AUTHOR: OPERATOR_BAGAS [← KEMBALI KE INDEKS REKAYASA LOG]