Tuesday, June 16, 2026

Open port 8080 for WebSocket

 

To open port 8080 on an Apache2 server running on Ubuntu for WebSocket communication, you must configure Apache to listen on that port, enable the proxy tunnel modules, and allow the traffic through your system firewall. [1, 2, 3]
1. Enable Apache WebSocket Modules [1]
You must first enable the proxy and WebSocket tunnel modules so Apache can route connection upgrades. Run the following commands: [1]
bash
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_wstunnel
sudo a2enmod rewrite

2. Configure Apache to Listen on Port 8080 [1]
Tell Apache to actively monitor port 8080 alongside its default ports. [1, 2]
  1. Open the ports configuration file:
    bash
    sudo nano /etc/apache2/ports.conf
    

  2. Add Listen 8080 below the existing Listen 80 line:
    apache
    Listen 80
    Listen 8080
    

  3. Save and close the file (Ctrl+O, Enter, then Ctrl+X). [1, 2, 3, 4, 5]
3. Set Up the WebSocket Virtual Host [1]
Create or modify a virtual host configuration file to capture traffic on port 8080 and forward it to your local WebSocket application. [1, 2]
  1. Open your virtual host file (replace 000-default.conf with your actual site file if different):
    bash
    sudo nano /etc/apache2/sites-available/000-default.conf
    

  2. Append a new block at the bottom of the file. Change ws://127.0.0.1:9000 to the actual internal IP and port where your backend WebSocket application (e.g., Node.js, Python, or Ratchet) is listening:
    apache
    <VirtualHost *:8080>
        ServerName yourdomain.com
    
        ProxyRequests Off
        ProxyPreserveHost On
    
        # Proxy WebSocket connections to your backend app
        ProxyPass / ws://127.0.0.1:9000/
        ProxyPassReverse / ws://127.0.0.1:9000/
    </VirtualHost>
    

  3. Save and close the file. [1, 2, 3, 4, 5]
4. Open Port 8080 in the Ubuntu Firewall (UFW) [1]
By default, the Ubuntu firewall blocks outside connections to high ports. Use the Uncomplicated Firewall (UFW) to allow inbound TCP traffic: [1, 2, 3, 4, 5]
bash
sudo ufw allow 8080/tcp
sudo ufw reload

5. Restart Apache [1]
Apply all structural changes by restarting the Apache web service: [1, 2]
bash
sudo systemctl restart apache2

6. Verify the Port is Open [1]
Confirm that Apache is successfully binding to the port with netstat: [1, 2, 3]
bash
sudo netstat -tuln | grep 8080

Note: If your server is hosted on a cloud provider like AWS, Google Cloud, or Azure, you must also add an Inbound Security Rule in their web dashboard to let port 8080 traffic pass through their platform firewalls. [1, 2]

No comments:

Blog Archive

Followers