Proxying WebSockets on NodeJS running off Apache

Disclaimer: I’m not a WebServer Admin/Pro and only tinker with stuff found around, so please excuse my ignorance or wrong jargon used here.

I had this terrible problem where a NodeJS app running on port 3000 on an Apache Server would refuse to proxy the incoming Web Sockets to the Node App. After almost two weeks of battling it out (including Server upgrades and losing out the entire app :), we finally managed to get it running). I’ll start off with my setup and then come over to the solution. If you’d like to directly jump to the solution, please scroll down.


I’m building an IoT gateway that allows for bi-directional communication between nodes/sensors (Arduino based) and decided to experiment with NodeJS to build the Backend (and Frontend) server. Since I’m moderately comfortable with Apache (and running WordPress etc on it), the first thing I did was install Apache on my Debian 7 instance which is running off on Linode. (The folks at Linode have a bunch of awesome tutorials that take you through the process of getting started with a Server, configuring (L)AMP stack and much more).

Finally, we got our NodeJS App running on Port 3000 (looks like that port is a default standard out there) and our Apache server live on port 80.

Now came the funny part: We needed a sub domain which would redirect to the NodeJS app running on Port 3000. We played around a while with Virtual Hosts in the Apache Site config file and all went well… Until I found out that Web Sockets weren’t being properly proxied back to port 3000 from while would work just fine.


After banging my head around for many days (2-3 weeks in-fact), I found the following solution on StackOverflow:

It turned out, I was running Apache 2.2 that didn’t support mod_proxy_tunnel module and had to either build it off the Apache 2.4 sources and patch it or get the instance running on Debian 8 which supports Apache 2.4 out of the box. I thought building it from scratch on Jessie (Debian 8) would be a better solution instead of patching and messing around.

After a couple of hours, finally got those Web Sockets working.


Pictured above is a screengrab of the conf file that we had to modify to get Web Sockets proxy working (after enabling (mod_proxy  and mod_proxy_wstunnel).

Since my NodeJS app was handling WebSockets at, I decided to only ProxyPass that particular path instead of the document root (as shown in stackoverflow answer above).

Now I have a nice server listening/tunneling (I don’t even know much about Web Sockets yet to use the right word here) to Web Sockets of a NodeJS app on port 3000.


Author: Anwaarullah

Designer, Developer, Maker, Speaker, Educator and Dreamer. ♥ Tinkering with Embedded, Android, Open Soft/Hard/Firm ware, Robotics and 3D Printer. Talk to me at syed {Shift+2} anwaarullah dash com

2 thoughts on “Proxying WebSockets on NodeJS running off Apache”

  1. Thank you Anwaarullah, I didn’t understand how this worked inside the apache virtual host configuration.
    I noticed you split your entries into 2 virtual host directives. Because my virtual machine doesn’t have a domain name to work with I assumed I needed things to work within the first directive. What follows is the default host file from installin apache minus their howto comments and plus changes I made per your suggestions. /echoxx acts like a service name.

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    ProxyPass /echoxx http://localhost:9000/

    ProxyPassReverse /echobot http://localhost:9000/

    ProxyPass “ws://localhost:9000/echoxx”

    # ProxyPass / fcgi://

    I tried many variations before arriving at a successful solution using your example.

    Thank you so much,
    Chris Silkey

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.