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]
3. Set Up the WebSocket Virtual Host [1]
- Open your virtual host file (replace
000-default.confwith your actual site file if different):bashsudo nano /etc/apache2/sites-available/000-default.conf - Append a new block at the bottom of the file. Change
ws://127.0.0.1:9000to 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> - Save and close the file. [1, 2, 3, 4, 5]
4. Open Port 8080 in the Ubuntu Firewall (UFW) [1]
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]
bash
sudo netstat -tuln | grep 8080
No comments:
Post a Comment