HenningM / express-ws

WebSocket endpoints for express applications
BSD 2-Clause "Simplified" License
871 stars 140 forks source link

Usage behind a apache/nginx reverse proxy #128

Open tzvc opened 4 years ago

tzvc commented 4 years ago

Hi there,

I'm trying to use express-ws on my application sitting behind a Apache2 reverse proxy but I can't get it to work, I keep getting

WebSocketException: Connection to 'https://blablamyapi.net/ws' was not upgraded to websocket

Thing is everything works properly on local so I suspect that the problem is the reverse proxy on my remote server is not letting the websocket upgrade requests through properly. I tried a few solution found online for my apache config:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName blablamyapi.te
    ServerAlias blablamyapi.te

    ProxyPreserveHost On

    RewriteEngine on
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule .* "wss://0.0.0.0:3030%{REQUEST_URI}" [P]

    ProxyPass / http://0.0.0.0:3030/
    ProxyPassReverse / http://0.0.0.0:3030/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
</IfModule>

Have anyone manage to do this before? What am I missing here?

taxilian commented 4 years ago

does your apache server support websocket tunneling? A quick google search came up with https://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html