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

    • How to Secure Sudo in Linux (Secure Sudo Logging & Timeout)
    • Make Fedora Login Safe with Authselect and Faillock
    • How Measure Linux Security Use OpenSCAP Lynis and Systemd
    • SELinux Make Nginx Break and How to Fix It Easy
    • How See Hidden SELinux Errors When Your Server Is Broken
    • How Fix SELinux Port Denied Error With Sealert Easy Guide
    • Read SELinux AVC Denial Log Simple Guide for Noob
    • How Check and Fix SELinux Block Things in Fedora Linux
    • How Actually SELinux is Work?
    • How to Install Elementary OS 8 Easy and Make It Good
    • How to Install UniFi OS Server on Ubuntu Linux Without Cloud Key
    • Top DNF5 Tips to Make Your Fedora Linux Super Fast
    • Run Local AI on Fedora 44 CPU Without Expensive GPU
    • Google Gemini Live Redesign: Works with more ‘Connected Apps’ on Android
    • A new LILYGO T3S3 ESP32-S3 with LoRA, WiFi & Bluetooth is Released only $16
    • New ESP32 Project: OpenTrafficMap ESP32-C5 C-ITS With 802.11p V2X communication
    • How to Unlock the Hidden Potential of Your Kindle with Amazing Community Plugins
    • How to Use Waze with Android Auto for the Ultimate Driving Experience
    • How to Transform Your GNOME Desktop with GNOME Prism
    • Why Your Google Maps Wear OS Navigation Fails While Using Android Auto
    • Packagist Attacked! How to Detect Hidden Malware Like This?
    • Claude Mythos Keeps Find High-severity Flaws, What You Should You Do?
    • How to Secure Your PHP Applications Against the Recent Laravel-Lang Supply Chain Attack and Credential Stealers
    • How to Protect Your Server from the LiteSpeed cPanel Plugin Privilege Escalation Vulnerability
    • How to build a high-performance private photo cloud with Immich and TrueNAS SCALE
    • Inilah Cara Membuat File Koneksi RDP Secara Manual Biar Akses Remote Kalian Nggak Error Lagi
    • Inilah Cara Clear RDP Cache dan Registry MRU Biar Remote Desktop Kalian Kembali Segar
    • Cara Restore File Association .rdp Agar Remote Desktop Bisa Terbuka Otomatis Lagi
    • Apa itu Probabilistic Methods dalam Klasifikasi Data?
    • Apa itu Klasifikasi Data dengan Metode Feature Selection?
    • How to Automate Your Entire SEO Strategy Using a Swarm of 100 Free AI Agents Working in Parallel
    • How to create professional presentations easily using NotebookLM’s AI power for school projects and beyond
    • How to Master SEO Automation with Google Gemini 3.1 Flash-Lite in Google AI Studio
    • How to create viral AI video ads and complete brand assets using the Claude and Higgsfield MCP integration
    • How to Transform Your Mac Into a Supercharged AI Assistant with Perplexity Personal Computer
    RSS Error: WP HTTP Error: A valid URL was not provided.
    ©2026 Tutorial emka | Design: Newspaperly WordPress Theme