WebSocket Apache Proxy

I recently installed a cool tool called Node-RED which is a neat visual coding tool for IoT-type devices. It uses node.js, and listens on port 1880.  However, I wanted Node-RED to function over port 80, to avoid having to type a port as part of the URL. I struggled getting the WebSocket connection to function correctly. I kept getting a HTTP response of 500.


I figured I might be able to save some other folks the trouble (and help me remember for next time). To get this to work on a system running Apache, you’re going to need to enable a few modules.  I’m running Apache 2.4 on Raspbian Jessie for context.

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_wstunnel
sudo a2enmod proxy_html
sudo a2enmod proxy_fcgi


And configure your site listener to include the lines:

ProxyPreserveHost On
ProxyRequests Off

ProxyPass /nodered http://localhost:1880
ProxyPass /nodered/comms ws://localhost:1880/comms

ProxyPassReverse /nodered http://localhost:1880
ProxyPassReverse /nodered/comms ws://localhost:1880/comms


I learned where the WebSocket connection failed by watching the Javascript console in Chrome – it points you to the /comms directory, so you need to enable the WebSocket proxy there.

This way, you can simply navigate to your Node-RED installation on port 80 by simply using the URL http:///nodered/


Comments are closed.