8

I have a website hosted on lighttpd, accessible at the "www" subdomain. I also have a chat server listening on port 8124 made with node.js and socket.io.

I want all client traffic to happen on port 80, by redirecting all requests to the "chat" subdomain to port 8124. So I enabled mod_proxy and in lighttpd.conf I added:

$HTTP["host"] == "chat.myserver.com" {
    proxy.server = (
            "" => ((
                    "host" => "78.128.79.192",
                    "port" => "8124"
            ))
    )
}

On the client, when I connect to the websocket,

var socket = io.connect('http://chat.myserver.com');

I get the right messages from node.js:

debug - client authorized
info  - handshake authorized 6067470561567883577
debug - setting request GET /socket.io/1/websocket/6067470561567883577
debug - set heartbeat interval for client 6067470561567883577
debug - client authorized for 
debug - websocket writing 1::

But the browser gives an error:

Firefox can't connect to server ws://chat.myserver.com/socket.io/1/websocket/6067470561567883577

Of course, everything works correctly if I connect directly to the port 8124:

var socket = io.connect('http://www.myserver.com:8124');

But, as I said, I would like all client traffic to be on port 80. Is it possibile?

lortabac
  • 589
  • 4
  • 16

1 Answers1

8

mod_proxy is known to be not compatible with websockets.

HAProxy is compatible (I haven't tested it myself but here's an article on its configuration for websockets).

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • 3
    I've just installed Haproxy and it's working perfectly. Thank you – lortabac Jun 08 '12 at 11:45
  • You're welcome. And thanks for the confirmation as I hadn't tested it (as I said) and was looking forward to do it :) – Denys Séguret Jun 08 '12 at 11:48
  • Hi! I'm currently trying to make websocket with socket.io works with lighttpd and I'm facing an issue. It seems it can't connect to `ws:///socket.io/1// : 'Connection' header is missing`. What is your conf file of HAProxy as you said it works with it (instead of lighttp mod_proxy). Many thanks! – D4V1D Mar 25 '14 at 04:19
  • I installed HAProxy and it works like a charm. Thanks! – D4V1D Mar 25 '14 at 14:01
  • 3
    This solution is not really *websocket traffic on port 80 with lighttpd* but rather *websocket traffic on port 80* **without** *lighttpd*.In the linked article lighttpd (or any other webserver) listens on port 8080 and is not involved in serving ws connections in any way. – TNT Dec 08 '14 at 09:11