2

Trying my luck her as StackOverflow was not the right place to ask. Hopefully this is where my question belongs!

I have been pulling my hair the last few days getting websockets to work with Apache2.4. I finally found a solution that worked for me, namely the following:

<VirtualHost *:80>
  ServerName www.domain2.com

  RewriteEngine On
  RewriteCond %{REQUEST_URI}  ^/socket.io            [NC]
  RewriteCond %{QUERY_STRING} transport=websocket    [NC]
  RewriteRule /(.*)           ws://localhost:3001/$1 [P,L]

  ProxyPass / http://localhost:3001/
  ProxyPassReverse / http://localhost:3001/
</VirtualHost>

The problem? Well, as soon as I switch over to wss, I am out of luck. At first, I hoped I could just change ws to wss above, but that didn't do the trick, I still get a 500 error. What might I be missing? (I use socket.io and the request looks like this: wss://xxx.yy/socket.io/?auth=YYY&EIO=3&transport=websocket&sid=XXX

0

1 Answer 1

4

I recently had almost exactly the same problem. It worked with HTTP and WS, but when I switched to HTTPS and WSS it stopped working. I fiddled around a bit, and somehow made it work. This is my working config:

<VirtualHost *:443>
  ServerName blabla

  #SSL-stuff
  ...

  # I don't think this is important but it's there
  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  # Here's the fun stuff
  <Location />
    RewriteEngine on
    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
    RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
    RewriteRule .* ws://localhost:3002%{REQUEST_URI} [P,L]

    ProxyPass http://localhost:3001/
    ProxyPassReverse http://localhost:3001/
  </Location>
</VirtualHost>

It's not that different from yours. Instead of looking for the path and query string of the websocket, it looks for the Upgrade and Connection headers in the HTTP request, which tells that this is supposed to become a websocket.

The URL and query params will be handled by your application

I'm sorry I can't tell you exactly what is wrong, but hopefully my config will work in your case too

1
  • This worked for me! Thanks :) I also had to change the autobahn connection url param to url: "wss://myserver:443/path"
    – Bolli
    Sep 18, 2018 at 12:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .