Skip to content
Tutorial emka
Menu
  • Home
  • Debian Linux
  • Ubuntu Linux
  • Red Hat Linux
Menu

Tutorial Cara Menjalankan Aplikasi Real-Time dengan Apache dan WebSocket

Posted on October 28, 2024

Aplikasi modern seringkali memanfaatkan WebSocket untuk menghadirkan pengalaman real-time, seperti pembaruan langsung atau fitur chat. Jika aplikasi Anda dijalankan di server Apache, konfigurasi yang tepat diperlukan untuk menangani permintaan WebSocket (wss://). Panduan sederhana ini akan menunjukkan cara mengkonfigurasi Apache untuk menangani permintaan ini, mulai dari mengaktifkan modul yang tepat hingga menyesuaikan pengaturan VirtualHost.

  • WebSocket memungkinkan pesan dikirim dan diterima secara instan dalam aplikasi chat.

    Pembaruan data langsung:

  • WebSocket memungkinkan sinkronisasi permainan, seperti gerakan pemain dan pembaruan status.

    Konfigurasi Apache untuk WebSocket

    Misalnya, Anda memiliki aplikasi Next.JS yang berjalan di URL


    Langkah Konfigurasi:

      Aktifkan Modul yang Dibutuhkan:

      sudo a2enmod proxy
      sudo a2enmod proxy_http
      sudo a2enmod proxy_wstunnel
      sudo a2enmod rewrite
         

    1. Tambahkan konfigurasi berikut ke file VirtualHost Apache Anda (biasanya ditemukan di /etc/apache2/sites-available/):

      <VirtualHost *:80>
          ServerName example.com
      
          # Konfigurasi lainnya (seperti DocumentRoot, dll.)
      
          # Proxy koneksi WebSocket
          RewriteEngine On
          RewriteCond %{HTTP:Upgrade} =websocket [NC]
          RewriteRule /(.*) wss://localhost:3000/$1 [P,L]
      
          # Proxy permintaan HTTP lainnya
          ProxyPass / http://localhost:3000/
          ProxyPassReverse / http://localhost:3000/
      </VirtualHost>
          

      Dalam konfigurasi ini:

        RewriteRule:

      • Menangani lalu lintas HTTP biasa.
      • Setelah melakukan perubahan, restart Apache untuk menerapkan konfigurasi:

              sudo systemctl restart apache2
            

    Penjelasan Konfigurasi:

    Kode konfigurasi di atas mengatur bagaimana Apache menangani permintaan yang datang ke domain .

      mengaktifkan modul rewrite Apache, memungkinkan aturan untuk memanipulasi URL yang masuk.

      memeriksa apakah permintaan yang masuk memiliki header yang nilainya sama dengan . Ini berarti bahwa permintaan tersebut adalah permintaan WebSocket.

      mendefinisikan aturan untuk menangani permintaan WebSocket. Aturan ini mengambil semua permintaan yang sesuai dengan kondisi sebelumnya dan meneruskannya ke server yang menjalankan aplikasi WebSocket di .

      dan menangani permintaan HTTP biasa dengan meneruskan mereka ke server backend di .

      Kesimpulan:

      Dengan mengikuti langkah-langkah yang diuraikan dalam artikel ini, Anda dapat berhasil mengkonfigurasi Apache untuk menangani permintaan WebSocket (wss://), memastikan komunikasi yang lancar antara klien dan server backend. Dengan mengaktifkan modul yang diperlukan dan mengatur konfigurasi ProxyPass dan RewriteRule yang benar, Apache dapat secara efisien memproksi koneksi WebSocket serta mengelola lalu lintas HTTP biasa.

  • Recent Posts

    • Is it Time to Replace Nano? Discover Fresh, the Terminal Text Editor You Actually Want to Use
    • How to Design a Services Like Google Ads
    • How to Fix 0x800ccc0b Outlook Error: Step-by-Step Guide for Beginners
    • How to Fix NVIDIA App Error on Windows 11: Simple Guide
    • How to Fix Excel Formula Errors: Quick Fixes for #NAME
    • How to Clear Copilot Memory in Windows 11 Step by Step
    • How to Show Battery Percentage on Windows 11
    • How to Fix VMSp Service Failed to Start on Windows 10/11
    • How to Fix Taskbar Icon Order in Windows 11/10
    • How to Disable Personalized Ads in Copilot on Windows 11
    • What is the Microsoft Teams Error “We Couldn’t Connect the Call” Error?
    • Why Does the VirtualBox System Service Terminate Unexpectedly? Here is the Full Definition
    • Why is Your Laptop Touchpad Overheating? Here are the Causes and Fixes
    • How to Disable All AI Features in Chrome Using Windows 11 Registry
    • How to Avoid Problematic Windows Updates: A Guide to System Stability
    • What is Microsoft Visual C++ Redistributable and How to Fix Common Errors?
    • What is the 99% Deletion Bug? Understanding and Fixing Windows 11 File Errors
    • How to Add a Password to WhatsApp for Extra Security
    • How to Recover Lost Windows Passwords with a Decryptor Tool
    • How to Fix Python Not Working in VS Code Terminal: A Troubleshooting Guide
    • Game File Verification Stuck at 0% or 99%: What is it and How to Fix the Progress Bar?
    • Why Does PowerPoint Underline Hyperlinks? Here is How to Remove Them
    • AI Bug Hunting with Semgrep
    • What is the Excel Power Query 0xc000026f Error?
    • How to Build Your Own Homelab AI Supercomputer 2026
    • Inilah Deretan HP Vivo dengan Kamera Stabilizer Terbaik 2026, Cocok Banget Buat Konten Kreator Modal Minim!
    • Cara Mendapatkan Lead dan Rekomendasi SEO dari ChatGPT dan Claude (Update Tahun 2026)
    • Inilah Rekomendasi HP Infinix Kamera Bagus dan RAM Besar Paling Juara Buat Konten dan Gaming!
    • Inilah Trik Supaya Koneksi Indosat Makin Kencang, Tutorial Setting APN Terbaru 2026!
    • Inilah 7 HP Xiaomi NFC Termurah 2025, Dompet Aman Aktivitas Tetap Lancar!
    • How to use Gamma AI as a complete design engine for professional presentations and graphics
    • A beginner tutorial on the Claude Advisor: Learn how to boost your AI agent’s intelligence with the advisor strategy
    • Complete tutorial on building a powerful AI knowledge graph with Obsidian and Claude Code
    • Complete Tutorial: How to Master New Google Gemini’s New Interactive 3D Visualizations and Simulations
    • How to Coordinate Multiple AI Agents with the Claude Teams Observer Pattern: A Step-by-Step Tutorial
    • Apa itu Spear-Phishing via npm? Ini Pengertian dan Cara Kerjanya yang Makin Licin
    • Apa Itu Predator Spyware? Ini Pengertian dan Kontroversi Penghapusan Sanksinya
    • Mengenal Apa itu TONESHELL: Backdoor Berbahaya dari Kelompok Mustang Panda
    • Siapa itu Kelompok Hacker Silver Fox?
    • Apa itu CVE-2025-52691 SmarterMail? Celah Keamanan Paling Berbahaya Tahun 2025
    ©2026 Tutorial emka | Design: Newspaperly WordPress Theme