NodeJs Error during WebSocket handshake

I am able to establish a websocket connection, from a clienJS to NodeJs. But fails to connect websocket, when the request pass through apache httpd.

Using Httpd2.4.7, I am getting the below error. Please let me know what needs to be corrected.

WebSocket connection to 'ws://' failed: Error during WebSocket handshake: Unexpected response code: 502

Thanks & Regards



After 2.4.5, apache included a module called proxy_wstunnel on their trunk, not available yet on current ubuntu production versions of apache (2.4.7). It was somehow painful, but following roughly the steps listed on this blog-post I managed to install the module and use it successfully.

dpkg -s apache2 //this gives you the version of apache in my case "2.4.7-1ubuntu4.1"
//then you checkout that version of apache
svn co
//you get into the directory just checked out
cd 2.4.7
//in there you checkout the Apache Portable Runtime Project and utils
svn co srclib/apr
svn co srclib/apr-util
//you compile with the corresponding modules flags
./configure --enable-proxy=shared --enable-proxy_wstunnel=shared

//You copy the modules (mod_proxy and mod_proxy_wstunnel) to your apache working copy
//It could be advisable to backup the old mods first
sudo cp modules/proxy/.libs/mod_proxy{_wstunnel,}.so /usr/lib/apache2/modules/
sudo chmod 644 /usr/lib/apache2/modules/mod_proxy{_wstunnel,}.so
sudo echo -e "# Depends: proxy\nLoadModule proxy_wstunnel_module /usr/lib/apache2/modules/" | sudo tee -a /etc/apache2/mods-available/proxy_wstunnel.load

//you then enable your module and restart your apache... so now the module is ready to use
sudo a2enmod proxy_wstunnel
sudo service apache2 restart

and after all that, researching a little bit I found this page I configured my apache vhost file accordingly like this

<VirtualHost *:80>
    Redirect permanent /

<VirtualHost *:443>

    ProxyRequests off

        <Proxy *>
            Order deny,allow
            Allow from all

    ProxyPreserveHost On
//these next two lines are to enable the wstunnel
    ProxyPass / ws://localhost:9091/
    ProxyPassReverse / ws://localhost:9091/
//this line is to retrieve the to use
    ProxyPass / http://localhost:9091/

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/yourcert.crt
    SSLCertificateKeyFile /etc/ssl/private/yourcert.key
    SSLCertificateChainFile /etc/ssl/certs/your_bundle.crt

    //your logs
    CustomLog /var/log/apache2/ combined
    ErrorLog /var/log/apache2/

And TaDaaa... I have a working node websocket responding on port 9091 through an apache proxy that gets everything trough the 443 standard ssl port.

I suppose ubuntu will soon include this module on their production version, but meanwhile this is the way to go

Apache SUCKS at handling websockets through proxies. I recommend either getting rid of the Apache layer, or modifying your settings to use XHR polling.

I had to setup ws tunnel in CentOs, where apache 2.2.15 was installed by default.

I have tried patching proxy_wstunnel module with apache 2.2.15. But no help. Finally I have decided to remove apache 2.2.15 and install apache 2.4 by following the official documentation from

After installation (I have installed in the default location /usr/local/apache2/), I did the following to get tunneling work

  1. uncomment the following lines from /usr/local/apache2/conf/httpd.conf

    LoadModule proxy_module modules/ LoadModule proxy_wstunnel_module modules/

  2. Add a virtual host for tunneling websocket requests

<VirtualHost *:80>
    ProxyPass / ws://localhost:8081/
    ProxyPassReverse / ws://localhost:8081/

from my frontend the websocket is connected via ws://

  1. restart apache using sudo /usr/local/apache2/bin/apachectl -k restart

Need Your Help

Using a System.Diagnostics.Process to Launch a Third Party Application

c# process singleton

All, I am developing an application that needs to launch another application at run-time. To launch the third-party app I am using System.Diagnostics.Process and to ensure I never launch the third-...

Can't add css in Magento

php html css magento xhtml

Have a custom template for my home page placed in mytheme/layout/page/customhome.phtml