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-BAB7LEVELWeb ServerWAKTU75 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
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 websiteadmin@server:~$ sudo mkdir -p /var/www/example.com/public_html# Set permissionadmin@server:~$ sudo chown -R www-data:www-data /var/www/example.comadmin@server:~$ sudo chmod -R 755 /var/www/example.com# Buat file index.htmladmin@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 configurationadmin@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 hostadmin@server:~$ sudo a2ensite example.com.conf# Disable default virtual host (optional)admin@server:~$ sudo a2dissite 000-default.conf# Test konfigurasiadmin@server:~$ sudo apache2ctl configtest# Reload Apacheadmin@server:~$ sudo systemctl reload apache2
Nginx Server Block
bash
# Buat directory untuk websiteadmin@server:~$ sudo mkdir -p /var/www/example.com/html# Set permissionadmin@server:~$ sudo chown -R www-data:www-data /var/www/example.comadmin@server:~$ sudo chmod -R 755 /var/www/example.com# Buat file index.htmladmin@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 configurationadmin@server:~$ sudo nano /etc/nginx/sites-available/example.comserver { 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 blockadmin@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 konfigurasiadmin@server:~$ sudo nginx -t# Reload Nginxadmin@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.
# Buat directory baru untuk document rootadmin@server:~$ sudo mkdir -p /var/www/mysite/html# Set permissionadmin@server:~$ sudo chown -R www-data:www-data /var/www/mysiteadmin@server:~$ sudo chmod -R 755 /var/www/mysite# Edit server block configurationadmin@server:~$ sudo nano /etc/nginx/sites-available/mysiteserver { 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 blockadmin@server:~$ sudo ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/# Test konfigurasiadmin@server:~$ sudo nginx -t# Reload Nginxadmin@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 rootadmin@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 directoryadmin@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 fileadmin@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/uploadssudo chmod -R 775 /var/www/mysite/cache# Verifikasi permissionadmin@server:~$ ls -la /var/www/mysite
Permission Explanation
PERMISSION
ANGKA
ARTI
755
rwxr-xr-x
Directory: owner bisa read/write/execute, group dan other bisa read/execute
644
rw-r--r--
File: owner bisa read/write, group dan other bisa read
775
rwxrwxr-x
Directory: owner dan group bisa read/write/execute, other bisa read/execute
777
rwxrwxrwx
Semua 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 rootadmin@server:~$ sudo chown -R www-data:www-data /var/www/mysiteadmin@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/mysitelocation / { autoindex off; try_files $uri $uri/ =404;}# Reload web serveradmin@server:~$ sudo systemctl reload apache2admin@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 configurationadmin@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 hostadmin@server:~$ sudo a2ensite example.com.conf# Test konfigurasiadmin@server:~$ sudo apache2ctl configtest# Reload Apacheadmin@server:~$ sudo systemctl reload apache2
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!
Volume 11 dari seri Debian Linux Server Fundamental - 7 sub-bab Web Server Fundamental.
Fitur Utama:
- Sidebar TOC: Klik sub-bab untuk lompat
- Prev/Next: Tombol navigasi di bawah
- Bookmark: Tandai sub-bab favorit
- Progress Bar: Indikator kemajuan baca
- Copy Code: Klik SALIN untuk copy command
7 Sub-Bab:
01: Konsep Web Server | 02: Apache vs Nginx | 03: Virtual Host | 04: Document Root | 05: Permission Website | 06: Konfigurasi Dasar | 07: Testing Web Server