Redirecting websocket traffic on port 80 with lighttpd
Asked Answered
S

1

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?

Sara answered 8/6, 2012 at 10:39 Comment(0)
H
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).

Holoenzyme answered 8/6, 2012 at 11:3 Comment(5)
I've just installed Haproxy and it's working perfectly. Thank youSara
You're welcome. And thanks for the confirmation as I hadn't tested it (as I said) and was looking forward to do it :)Tattered
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://<mydomain.com>/socket.io/1/<randomNumbers>/ : '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!Briareus
I installed HAProxy and it works like a charm. Thanks!Briareus
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.Chainsmoke

© 2022 - 2024 — McMap. All rights reserved.