A practical session on how Apache and Nginx actually work, how to configure a virtual host or server block, and how to diagnose the errors you'll hit running a website on a Hostinger VPS plan. Sesi praktis tentang cara kerja Apache dan Nginx, cara konfigurasi virtual host atau server block, dan cara mendiagnosis error yang bakal kamu temui saat menjalankan website di VPS Hostinger.
A web server's job is simple to describe: take a request from a visitor's browser, pull the right files, send a response back. Apache and Nginx do that same job with fundamentally different internal architecture.Tugas web server sebenarnya simpel: ambil request dari browser visitor, ambil file yang tepat, kirim balik responnya. Apache dan Nginx melakukan tugas yang sama tapi dengan arsitektur internal yang beda banget.
.htaccess config means no server restart needed. Nginx takes a bit more setup but scales much further on the same VPS resources, which matters for campaign or checkout traffic spikes.
Apache titik awal yang lebih mudah untuk website kecil — WordPress langsung jalan, dan config per-folder lewat .htaccess berarti nggak perlu restart server. Nginx butuh sedikit lebih banyak setup tapi jauh lebih scalable dengan resource VPS yang sama, penting banget kalau ada lonjakan traffic campaign atau checkout.
Both servers extend themselves through modules — but where that config lives, and how it's applied, is very different.Kedua server memperluas fungsinya lewat modul — tapi di mana config-nya disimpan, dan bagaimana diterapkan, sangat berbeda.
a2enmod rewrite on Ubuntu). Commonly used ones:
Modul diaktifkan di level server (mis. a2enmod rewrite di Ubuntu). Yang sering dipakai:
mod_rewrite — URL rewriting (WordPress/Laravel pretty links)rewrite URL (link cantik WordPress/Laravel)mod_ssl — HTTPS/TLS supportdukungan HTTPS/TLSmod_headers — response headers, CORS, caching rulesheader response, CORS, aturan caching.htaccess lets you override config per-folder without restarting the whole server — ideal for shared hosting, but every request checks these files, adding overhead..htaccess memungkinkan override config per-folder tanpa restart seluruh server — cocok untuk shared hosting, tapi setiap request mengecek file ini, jadi ada overhead.
.htaccess equivalent. All routing and behavior lives in config files under /etc/nginx/sites-available/, which means Nginx fails to start on a config error instead of silently misbehaving — a change requires systemctl reload nginx.
Nginx tidak punya padanan .htaccess. Semua routing dan behavior ada di file config di /etc/nginx/sites-available/, artinya Nginx akan gagal start kalau ada error config, bukan diam-diam salah jalan — perubahan butuh systemctl reload nginx.
location blocks and applied on reload.Di Nginx, aturan level-folder (redirect, auth) ditulis langsung di dalam blok location pada server block dan diterapkan saat reload.A virtual host tells Apache which folder and domain to serve. Here's the standard flow on a fresh Hostinger VPS (Ubuntu).Virtual host memberi tahu Apache folder dan domain mana yang harus dilayani. Ini alur standar di VPS Hostinger baru (Ubuntu).
/etc/apache2/sites-available/example.com.conf
apache2ctl configtest before reloading — Apache will still start with a broken config in some cases, and you want to catch a typo (like a missing </VirtualHost>) before it causes a 500 error for visitors.
Selalu jalankan apache2ctl configtest sebelum reload — Apache kadang tetap start meski config-nya rusak, dan kamu mau menangkap typo (seperti </VirtualHost> yang hilang) sebelum bikin visitor kena error 500.
Nginx needs one extra piece Apache doesn't: a working connection to PHP-FPM, since Nginx never executes PHP itself.Nginx butuh satu hal tambahan yang Apache tidak perlukan: koneksi yang jalan ke PHP-FPM, karena Nginx sendiri tidak pernah mengeksekusi PHP.
/etc/nginx/sites-available/example.com
location ~ \.php$ block but forgetting to match the actual PHP-FPM socket path/version — this is the #1 cause of a 502 on a fresh Nginx setup.Copy blok location ~ \.php$ tapi lupa sesuaikan path socket/versi PHP-FPM yang sebenarnya — ini penyebab #1 error 502 di setup Nginx baru.ls /run/php/ to confirm the actual socket filename before pasting it into the config.Jalankan ls /run/php/ untuk memastikan nama file socket yang sebenarnya sebelum ditempel ke config.The same error code means something different depending on which server produced it — that's the single most useful thing to internalize for troubleshooting.Kode error yang sama bisa berarti beda tergantung server mana yang menghasilkannya — ini hal paling berguna yang perlu dipahami untuk troubleshooting.
.htaccess — one wrong character breaks the whole file.Hampir selalu typo di .htaccess — satu karakter salah merusak seluruh file.Deny from all in .htaccess, or wrong folder permissions.Deny from all di .htaccess, atau permission folder salah.tail -f /var/log/apache2/error.log oratau tail -f /var/log/nginx/error.log
When a site goes down on your VPS, work through these in order rather than guessing. Tap each step as you go.Kalau situs down di VPS-mu, kerjakan langkah ini secara urut, jangan menebak-nebak. Tap tiap langkah saat kamu jalankan.
apache2ctl configtest or nginx -t.apache2ctl configtest atau nginx -t.systemctl status php8.3-fpm), worker pool for Apache.systemctl status php8.3-fpm), worker pool untuk Apache.chmod/ownership) rather than assuming it's a config bug.chmod/ownership) daripada langsung asumsi bug config.systemctl reload apache2 / nginx.systemctl reload apache2 / nginx.Neither is "better" — the right choice depends on traffic pattern and how much config work you want to own.Nggak ada yang "lebih bagus" — pilihan yang tepat tergantung pola traffic dan seberapa banyak config yang mau kamu urus sendiri.
| DimensionDimensi | Apache | Nginx |
|---|---|---|
| Ease of setupKemudahan setup | ⭐⭐⭐⭐⭐ works instantlylangsung jalan | ⭐⭐⭐ needs PHP-FPM wiringperlu hubungkan PHP-FPM |
| PHP | mod_php (built in)(built in) | PHP-FPM (separate process)(proses terpisah) |
| Config locationLokasi config | Spread out, can use .htaccessTersebar, bisa pakai .htaccess | Centralized in /etc/nginx/Terpusat di /etc/nginx/ |
| Best forCocok untuk | Small/medium sites, WordPress, quick launchesWebsite kecil/menengah, WordPress, launching cepat | High traffic, campaigns, checkout spikes, static-heavy sitesTraffic tinggi, campaign, lonjakan checkout, situs banyak konten statis |
| Restart commandPerintah restart | systemctl restart apache2 | systemctl restart nginx |