ABDURROZAK
HOME ABOUT ME MICROSITE KONTAK PERSEMBAHAN HELP
ABDURROZAK.MY.ID // DEBIAN LINUX SERVER FUNDAMENTAL

WEB SERVERFUNDAMENTAL

Volume 11 dari seri Debian Linux Server Fundamental. Panduan komprehensif membangun web server dengan Apache dan Nginx. Setiap command dijelaskan detail dengan syntax, parameter, contoh penggunaan, dan output. Dari konsep web server hingga testing web server.

VOLUME11 / 17
SUB-BAB7
BACA75 MENIT
WEB SERVER100%
ABDUR ROZAK, S.Kom. Web Developer & Network Educator - abdurrozak.my.id
VOLUME 11 / 17

MEMBANGUN WEB SERVER DENGAN DEBIAN

Panduan lengkap Web Server Fundamental di Debian Linux. 7 sub-bab mencakup konsep web server, Apache vs Nginx, virtual host, document root, permission website, konfigurasi dasar website, hingga testing web server. Setiap command disertai penjelasan detail dan contoh praktis.
SUB-BAB7 LEVELWeb Server WAKTU75 MENIT
01
SUB-BAB 01 KONSEP

KONSEP WEB SERVER

Apa Itu Web Server?

Web server adalah software yang melayani permintaan HTTP/HTTPS dari client (browser) dan mengirimkan response berupa halaman web (HTML, CSS, JavaScript, gambar, dll). Web server menerima request dari client, memproses request tersebut, dan mengirimkan response kembali ke client.

Cara Kerja Web Server

1
REQUEST-RESPONSE CYCLE

Langkah 1: Client (browser) mengirim HTTP request ke web server

Langkah 2: Web server menerima request dan memproses

Langkah 3: Web server mencari file yang diminta atau memproses dynamic content

Langkah 4: Web server mengirim HTTP response kembali ke client

Langkah 5: Client menerima response dan menampilkan halaman web

Komponen Web Server

KOMPONENFUNGSICONTOH
Web Server SoftwareMelayani HTTP requestApache, Nginx, Lighttpd
Document RootDirectory tempat file web disimpan/var/www/html
Virtual HostKonfigurasi untuk multiple websiteVirtualHost directive
ModulesModul untuk menambah fiturmod_php, mod_ssl, mod_rewrite
Configuration FilesFile konfigurasi web serverapache2.conf, nginx.conf

HTTP Request & Response

HTTP Request
# HTTP Request Format GET /index.html HTTP/1.1 Host: www.example.com User-Agent: Mozilla/5.0 Accept: text/html # HTTP Response Format HTTP/1.1 200 OK Content-Type: text/html Content-Length: 1234 <html> <body> <h1>Hello World</h1> </body> </html>

HTTP Methods

METHODFUNGSIUSE CASE
GETMengambil resourceMengambil halaman web
POSTMengirim data ke serverSubmit form
PUTUpdate resourceUpdate resource
DELETEHapus resourceHapus resource
HEADSama dengan GET tapi tanpa bodyCek header saja

HTTP Status Codes

CODEARTIDESKRIPSI
200OKRequest berhasil
301Moved PermanentlyRedirect permanen
302FoundRedirect sementara
304Not ModifiedResource tidak berubah (cache)
400Bad RequestRequest tidak valid
401UnauthorizedPerlu autentikasi
403ForbiddenAkses ditolak
404Not FoundResource tidak ditemukan
500Internal Server ErrorError di server
503Service UnavailableServer tidak tersedia
TIPS: Pahami HTTP status codes untuk debugging. 2xx = success, 3xx = redirect, 4xx = client error, 5xx = server error.
KOMPETENSI SUB-BAB 01
  • Memahami konsep web server
  • Memahami cara kerja request-response
  • Memahami HTTP methods dan status codes
  • Memahami komponen web server
02
SUB-BAB 02 WEB SERVER

APACHE VS NGINX

Perbandingan Apache dan Nginx

ASPEKAPACHENGINX
ArchitectureProcess/thread per connectionEvent-driven, asynchronous
PerformanceBaik untuk low trafficLebih baik untuk high traffic
Memory UsageLebih tinggiLebih rendah
Configuration.htsupport, flexiblenginx.conf, more structured
ModulesDynamic modules, .htaccessDynamic modules, no .htaccess
Static ContentBaikSangat baik
Dynamic ContentSangat baik (mod_php)Baik (via FastCGI)
PopularityPopuler, banyak dokumentasiSangat populer, modern

Install Apache

bash
# Install Apache admin@server:~$ sudo apt update admin@server:~$ sudo apt install apache2 # Start Apache admin@server:~$ sudo systemctl start apache2 # Enable Apache start on boot admin@server:~$ sudo systemctl enable apache2 # Cek status Apache admin@server:~$ sudo systemctl status apache2 # Cek versi Apache admin@server:~$ apache2 -v # Lihat modules yang aktif admin@server:~$ apache2ctl -M # Restart Apache admin@server:~$ sudo systemctl restart apache2 # Reload Apache (tanpa restart) admin@server:~$ sudo systemctl reload apache2

Install Nginx

bash
# Install Nginx admin@server:~$ sudo apt update admin@server:~$ sudo apt install nginx # Start Nginx admin@server:~$ sudo systemctl start nginx # Enable Nginx start on boot admin@server:~$ sudo systemctl enable nginx # Cek status Nginx admin@server:~$ sudo systemctl status nginx # Cek versi Nginx admin@server:~$ nginx -v # Test konfigurasi Nginx admin@server:~$ sudo nginx -t # Restart Nginx admin@server:~$ sudo systemctl restart nginx # Reload Nginx (tanpa restart) admin@server:~$ sudo systemctl reload nginx

Struktur Directory

Apache Directory Structure
/etc/apache2/ ├── apache2.conf # Main configuration file ├── ports.conf # Port configuration ├── sites-available/ # Available virtual hosts │ ├── 000-default.conf # Default virtual host │ └── example.com.conf # Virtual host example ├── sites-enabled/ # Enabled virtual hosts (symlinks) │ └── 000-default.conf -> ../sites-available/000-default.conf ├── mods-available/ # Available modules ├── mods-enabled/ # Enabled modules (symlinks) └── conf-available/ # Additional configuration /var/www/ └── html/ # Default document root └── index.html # Default index file
Nginx Directory Structure
/etc/nginx/ ├── nginx.conf # Main configuration file ├── sites-available/ # Available virtual hosts │ └── default # Default virtual host ├── sites-enabled/ # Enabled virtual hosts (symlinks) │ └── default -> ../sites-available/default ├── conf.d/ # Additional configuration └── snippets/ # Configuration snippets /var/www/ └── html/ # Default document root └── index.nginx-debian.html
TIPS: Apache menggunakan .htaccess untuk per-directory configuration, sedangkan Nginx tidak support .htaccess. Semua konfigurasi Nginx harus di nginx.conf atau file konfigurasi virtual host.
KOMPETENSI SUB-BAB 02
  • Mampu install Apache dan Nginx
  • Mampu start/stop/restart web server
  • Memahami struktur directory Apache dan Nginx
  • Memahami perbedaan Apache dan Nginx
03
SUB-BAB 03 VIRTUAL HOST

VIRTUAL HOST

Apa Itu Virtual Host?

Virtual Host (Apache) atau Server Block (Nginx) adalah konfigurasi yang memungkinkan satu web server melayani multiple website dengan domain berbeda. Setiap virtual host memiliki document root, log files, dan konfigurasi tersendiri.

Apache Virtual Host

bash
# Buat directory untuk website admin@server:~$ sudo mkdir -p /var/www/example.com/public_html # Set permission admin@server:~$ sudo chown -R www-data:www-data /var/www/example.com admin@server:~$ sudo chmod -R 755 /var/www/example.com # Buat file index.html admin@server:~$ sudo nano /var/www/example.com/public_html/index.html <html> <head> <title>Welcome to Example.com</title> </head> <body> <h1>Welcome to Example.com!</h1> </body> </html> # Buat virtual host configuration admin@server:~$ sudo nano /etc/apache2/sites-available/example.com.conf <VirtualHost *:80> ServerAdmin webmaster@example.com ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com/public_html <Directory /var/www/example.com/public_html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/example.com_error.log CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined </VirtualHost> # Enable virtual host admin@server:~$ sudo a2ensite example.com.conf # Disable default virtual host (optional) admin@server:~$ sudo a2dissite 000-default.conf # Test konfigurasi admin@server:~$ sudo apache2ctl configtest # Reload Apache admin@server:~$ sudo systemctl reload apache2

Nginx Server Block

bash
# Buat directory untuk website admin@server:~$ sudo mkdir -p /var/www/example.com/html # Set permission admin@server:~$ sudo chown -R www-data:www-data /var/www/example.com admin@server:~$ sudo chmod -R 755 /var/www/example.com # Buat file index.html admin@server:~$ sudo nano /var/www/example.com/html/index.html <html> <head> <title>Welcome to Example.com</title> </head> <body> <h1>Welcome to Example.com!</h1> </body> </html> # Buat server block configuration admin@server:~$ sudo nano /etc/nginx/sites-available/example.com server { listen 80; listen [::]:80; root /var/www/example.com/html; index index.html index.htm; server_name example.com www.example.com; location / { try_files $uri $uri/ =404; } } # Enable server block admin@server:~$ sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ # Disable default server block (optional) admin@server:~$ sudo rm /etc/nginx/sites-enabled/default # Test konfigurasi admin@server:~$ sudo nginx -t # Reload Nginx admin@server:~$ sudo systemctl reload nginx
TIPS: Untuk testing lokal, tambahkan domain di /etc/hosts: 127.0.0.1 example.com www.example.com
KOMPETENSI SUB-BAB 03
  • Memahami konsep virtual host
  • Mampu konfigurasi Apache virtual host
  • Mampu konfigurasi Nginx server block
  • Mampu enable/disable virtual host
04
SUB-BAB 04 DOCUMENT ROOT

DOCUMENT ROOT

Apa Itu Document Root?

Document Root adalah directory tempat file-file website disimpan. Ketika user mengakses website, web server mencari file di document root. Document root default untuk Apache adalah /var/www/html dan untuk Nginx juga /var/www/html.

Mengubah Document Root

Apache - Change Document Root
# Buat directory baru untuk document root admin@server:~$ sudo mkdir -p /var/www/mysite/public_html # Set permission admin@server:~$ sudo chown -R www-data:www-data /var/www/mysite admin@server:~$ sudo chmod -R 755 /var/www/mysite # Edit virtual host configuration admin@server:~$ sudo nano /etc/apache2/sites-available/mysite.conf <VirtualHost *:80> ServerAdmin webmaster@mysite.com ServerName mysite.com DocumentRoot /var/www/mysite/public_html <Directory /var/www/mysite/public_html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/mysite_error.log CustomLog ${APACHE_LOG_DIR}/mysite_access.log combined </VirtualHost> # Enable virtual host admin@server:~$ sudo a2ensite mysite.conf # Reload Apache admin@server:~$ sudo systemctl reload apache2
Nginx - Change Document Root
# Buat directory baru untuk document root admin@server:~$ sudo mkdir -p /var/www/mysite/html # Set permission admin@server:~$ sudo chown -R www-data:www-data /var/www/mysite admin@server:~$ sudo chmod -R 755 /var/www/mysite # Edit server block configuration admin@server:~$ sudo nano /etc/nginx/sites-available/mysite server { listen 80; listen [::]:80; root /var/www/mysite/html; index index.html index.htm; server_name mysite.com www.mysite.com; location / { try_files $uri $uri/ =404; } } # Enable server block admin@server:~$ sudo ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/ # Test konfigurasi admin@server:~$ sudo nginx -t # Reload Nginx admin@server:~$ sudo systemctl reload nginx
TIPS: Selalu set permission yang benar untuk document root. Gunakan chown -R www-data:www-data dan chmod -R 755 untuk memastikan web server bisa membaca file.
KOMPETENSI SUB-BAB 04
  • Memahami konsep document root
  • Mampu mengubah document root Apache
  • Mampu mengubah document root Nginx
  • Mampu set permission yang benar
05
SUB-BAB 05 PERMISSION

PERMISSION WEBSITE

Permission yang Benar

Permission yang benar sangat penting untuk keamanan dan fungsionalitas website. Permission yang salah bisa menyebabkan website tidak bisa diakses atau rentan terhadap serangan.

Set Permission yang Benar

bash
# Set owner dan group untuk document root admin@server:~$ sudo chown -R www-data:www-data /var/www/mysite # www-data adalah user dan group yang digunakan oleh web server # Set permission untuk directory admin@server:~$ sudo find /var/www/mysite -type d -exec chmod 755 {} \; # 755 = rwxr-xr-x (owner: rwx, group: r-x, other: r-x) # Set permission untuk file admin@server:~$ sudo find /var/www/mysite -type f -exec chmod 644 {} \; # 644 = rw-r--r-- (owner: rw-, group: r--, other: r--) # Untuk directory yang perlu write access (upload, cache) admin@server:~$ sudo chmod -R 775 /var/www/mysite/uploads sudo chmod -R 775 /var/www/mysite/cache # Verifikasi permission admin@server:~$ ls -la /var/www/mysite

Permission Explanation

PERMISSIONANGKAARTI
755rwxr-xr-xDirectory: owner bisa read/write/execute, group dan other bisa read/execute
644rw-r--r--File: owner bisa read/write, group dan other bisa read
775rwxrwxr-xDirectory: owner dan group bisa read/write/execute, other bisa read/execute
777rwxrwxrwxSemua orang bisa read/write/execute (TIDAK DIREKOMENDASIKAN)
PERINGATAN: Jangan pernah gunakan permission 777 untuk directory atau file! Ini sangat berbahaya karena semua orang bisa write dan execute. Gunakan 755 untuk directory dan 644 untuk file.

Security Best Practices

bash
# Set permission yang aman untuk document root admin@server:~$ sudo chown -R www-data:www-data /var/www/mysite admin@server:~$ sudo find /var/www/mysite -type d -exec chmod 755 {} \; admin@server:~$ sudo find /var/www/mysite -type f -exec chmod 644 {} \; # Untuk directory upload (jika ada) admin@server:~$ sudo chmod 775 /var/www/mysite/uploads # Disable directory listing (Apache) admin@server:~$ sudo nano /etc/apache2/sites-available/mysite.conf <Directory /var/www/mysite> Options -Indexes AllowOverride All Require all granted </Directory> # Disable directory listing (Nginx) admin@server:~$ sudo nano /etc/nginx/sites-available/mysite location / { autoindex off; try_files $uri $uri/ =404; } # Reload web server admin@server:~$ sudo systemctl reload apache2 admin@server:~$ sudo systemctl reload nginx
TIPS: Selalu disable directory listing untuk mencegah user melihat isi directory. Gunakan Options -Indexes untuk Apache dan autoindex off untuk Nginx.
KOMPETENSI SUB-BAB 05
  • Mampu set permission yang benar untuk website
  • Memahami permission 755 dan 644
  • Mampu disable directory listing
  • Memahami security best practices
06
SUB-BAB 06 KONFIGURASI

KONFIGURASI DASAR WEBSITE

Konfigurasi Apache

Apache Virtual Host Configuration
# Buat virtual host configuration admin@server:~$ sudo nano /etc/apache2/sites-available/example.com.conf <VirtualHost *:80> # Server information ServerAdmin webmaster@example.com ServerName example.com ServerAlias www.example.com # Document root DocumentRoot /var/www/example.com/public_html # Directory configuration <Directory /var/www/example.com/public_html> Options -Indexes +FollowSymLinks AllowOverride All Require all granted </Directory> # Logging ErrorLog ${APACHE_LOG_DIR}/example.com_error.log CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined # Security headers <IfModule mod_headers.c> Header set X-Content-Type-Options "nosniff" Header set X-Frame-Options "SAMEORIGIN" Header set X-XSS-Protection "1; mode=block" </IfModule> </VirtualHost> # Enable virtual host admin@server:~$ sudo a2ensite example.com.conf # Test konfigurasi admin@server:~$ sudo apache2ctl configtest # Reload Apache admin@server:~$ sudo systemctl reload apache2

Konfigurasi Nginx

Nginx Server Block Configuration
# Buat server block configuration admin@server:~$ sudo nano /etc/nginx/sites-available/example.com server { listen 80; listen [::]:80; # Server information server_name example.com www.example.com; # Document root root /var/www/example.com/html; index index.html index.htm; # Location configuration location / { try_files $uri $uri/ =404; } # Security headers add_header X-Content-Type-Options "nosniff" always; add_header X-Frame-Options "SAMEORIGIN" always; add_header X-XSS-Protection "1; mode=block" always; # Logging access_log /var/log/nginx/example.com_access.log; error_log /var/log/nginx/example.com_error.log; } # Enable server block admin@server:~$ sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ # Test konfigurasi admin@server:~$ sudo nginx -t # Reload Nginx admin@server:~$ sudo systemctl reload nginx
TIPS: Selalu test konfigurasi sebelum reload. Gunakan apache2ctl configtest untuk Apache dan nginx -t untuk Nginx.
KOMPETENSI SUB-BAB 06
  • Mampu konfigurasi Apache virtual host
  • Mampu konfigurasi Nginx server block
  • Mampu enable/disable virtual host
  • Mampu test konfigurasi
07
SUB-BAB 07 TESTING

TESTING WEB SERVER

Testing Web Server

bash
# Cek status web server admin@server:~$ sudo systemctl status apache2 admin@server:~$ sudo systemctl status nginx # Test konfigurasi admin@server:~$ sudo apache2ctl configtest admin@server:~$ sudo nginx -t # Test dengan curl admin@server:~$ curl -I http://localhost HTTP/1.1 200 OK Date: Mon, 07 Sep 2026 10:30:15 GMT Server: Apache/2.4.57 (Debian) Content-Type: text/html # Test dengan curl (verbose) admin@server:~$ curl -v http://localhost # Test dengan wget admin@server:~$ wget http://localhost # Test dengan browser # Buka browser dan akses http://localhost atau http://server-ip # Cek log files admin@server:~$ sudo tail -f /var/log/apache2/access.log admin@server:~$ sudo tail -f /var/log/apache2/error.log admin@server:~$ sudo tail -f /var/log/nginx/access.log admin@server:~$ sudo tail -f /var/log/nginx/error.log

Testing Checklist

TESTCOMMANDEXPECTED RESULT
Web server statussystemctl status apache2active (running)
Configuration testapache2ctl configtestSyntax OK
Local accesscurl http://localhostHTTP 200 OK
Remote accesscurl http://server-ipHTTP 200 OK
Access logtail -f /var/log/apache2/access.logLog entries muncul
Error logtail -f /var/log/apache2/error.logTidak ada error

Troubleshooting Umum

MASALAHGEJALASOLUSI
Web server tidak start systemctl status menunjukkan failed Cek log error, test konfigurasi dengan apache2ctl configtest atau nginx -t
403 Forbidden Akses ditolak Cek permission document root, cek Directory directive
404 Not Found File tidak ditemukan Cek document root, cek file ada, cek Directory directive
500 Internal Server Error Error di server Cek error log, cek permission, cek .htaccess (Apache)
502 Bad Gateway Backend tidak tersedia Cek backend service (PHP-FPM, dll)
Port sudah digunakan Port 80 atau 443 sudah digunakan Cek dengan netstat -tulpn | grep :80, stop service lain atau ganti port
TIPS: Selalu cek error log untuk troubleshooting. Error log memberikan informasi detail tentang error yang terjadi.
KOMPETENSI SUB-BAB 07
  • Mampu test web server dengan curl dan wget
  • Mampu cek log files
  • Mampu troubleshoot masalah umum
  • Mampu test konfigurasi
VOLUME 11 SELESAI

SELAMAT!

Kamu telah menyelesaikan Volume 11 - Web Server Fundamental. Dari konsep web server, Apache vs Nginx, virtual host, document root, permission website, konfigurasi dasar website, hingga testing web server. Kamu sekarang menguasai Web Server Fundamental di Debian Linux. Di Volume 12, kita akan dalami Database Server. Sampai jumpa!
SUB-BAB7 LEVELWeb Server NEXTDatabase Server
ABDURROZAK.MY.ID // TERHUBUNG

JARINGAN SOSIAL

Temukan saya di berbagai platform digital